Package Manager > The system cannot find the file specified. (Exception from HRESULT: 0x80070002)

1

When getting the packages for my user i am getting "The system cannot find the file specified" in some InstalledLocation. Anyone knows why this happens? Are this apps broken? I need to get the InstalledLocation, is there anyway that i can do this without the try catch block? Thanks in advance

using System;
using System.IO;
using System.Security.Principal;
using Windows.Management.Deployment;
namespace ConsoleApp19
{
    class Program
    {
        static void Main(string[] args)
        {
            NTAccount acc = new NTAccount(WindowsIdentity.GetCurrent().Name);
            SecurityIdentifier sid = (SecurityIdentifier)acc.Translate(typeof(SecurityIdentifier));
            var packages = new PackageManager().FindPackagesForUser(sid.ToString());
            foreach (var package in packages)
            {
                Console.WriteLine(package.Id.FamilyName);
                try
                {
                    Console.WriteLine(package.InstalledLocation.Path);
                }
                catch (FileNotFoundException ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
            Console.ReadKey();
        }
    }
}

https://docs.microsoft.com/en-us/uwp/api/windows.management.deployment.packagemanager.findpackagesforuser

c#
.net
windows
uwp
asked on Stack Overflow Dec 20, 2018 by Ivan Valadares

1 Answer

0

Some apps that are installed in development mode throw error on acessing to installedLocation. To avoid this just check if they ate in development mode

if (!package.IsDevelopmentMode)
{
}
answered on Stack Overflow Mar 4, 2019 by Ivan Valadares

User contributions licensed under CC BY-SA 3.0