microsoft / msix-packaging

MSIX SDK
MIT License
963 stars 163 forks source link

UnauthorizedAccessException on PackageManager.AddPackageAsync #615

Open ironhide91 opened 4 months ago

ironhide91 commented 4 months ago

Project MSIX SDK

Describe the bug PackageManager.AddPackageAsync fails with exception :

System.UnauthorizedAccessException
  HResult=0x80070005
  Message=Attempted to perform an unauthorized operation.
  Source=WinRT.Runtime
  StackTrace:
   at WinRT.ExceptionHelpers.<ThrowExceptionForHR>g__Throw|39_0(Int32 hr)
   at ABI.Windows.Management.Deployment.IPackageManagerMethods.AddPackageAsync(IObjectReference _obj, Uri packageUri, IEnumerable`1 dependencyPackageUris, DeploymentOptions deploymentOptions)
   at Windows.Management.Deployment.PackageManager.AddPackageAsync(Uri packageUri, IEnumerable`1 dependencyPackageUris, DeploymentOptions deploymentOptions)
   at TenetQKato.AutoFile.Updater.UpdateTask.Run(PackageManager packageManager, Uri file) in C:\tenet\tenetqkato\TenetQKato\TenetQKato.AutoFile.Updater\UpdateTask.cs:line 18
   at TenetQKato.AutoFile.Updater.Updater.<RunAsync>d__2.MoveNext() in C:\tenet\tenetqkato\TenetQKato\TenetQKato.AutoFile.Updater\Updater.cs:line 35

From Debug :

Exception thrown at 0x00007FFC456BCF19 (KernelBase.dll) in App.exe: WinRT originate error - 0x80004005 : ''TenetQKato.AutoFile' violates pattern constraint of '\bms-resource:.{1,256}'.'.
Exception thrown at 0x00007FFC456BCF19 (KernelBase.dll) in App.exe: 0xE0000001 (parameters: 0xFFFFFFFF80004005).
Exception thrown at 0x00007FFC456BCF19 (KernelBase.dll) in App.exe: WinRT originate error - 0x80004005 : ''TENET Enterprises' violates pattern constraint of '\bms-resource:.{1,256}'.'.
Exception thrown at 0x00007FFC456BCF19 (KernelBase.dll) in App.exe: 0xE0000001 (parameters: 0xFFFFFFFF80004005).
Exception thrown at 0x00007FFC456BCF19 (KernelBase.dll) in App.exe: WinRT originate error - 0x80004005 : ''TenetQKato.AutoFile' violates pattern constraint of '\bms-resource:.{1,256}'.'.
Exception thrown at 0x00007FFC456BCF19 (KernelBase.dll) in App.exe: 0xE0000001 (parameters: 0xFFFFFFFF80004005).
onecore\printscan\appxpackaging\blockmap\src\appxblockmapreader.cpp(517)\AppxPackaging.dll!00007FFB6D11F943: (caller: 00007FFB6D11F3D6) ReturnHr(2) tid(3fec) 80070002 The system cannot find the file specified.
    Msg:[Filename: AppxContentGroupMap.xml] 
onecore\admin\appmodel\packagemanager\client\client.cpp(2755)\AppXDeploymentClient.dll!00007FFC3F5B14BC: (caller: 00007FFC3F5D7897) ReturnHr(1) tid(3fec) 80070005 Access is denied.
onecore\admin\appmodel\packagemanager\client\client.cpp(91)\AppXDeploymentClient.dll!00007FFC3F5D78E8: (caller: 00007FFB8F189716) ReturnHr(2) tid(3fec) 80070005 Access is denied.
Exception thrown: 'System.UnauthorizedAccessException' in WinRT.Runtime.dll

This msix package is created from .net 7.0 console application using "Windows Application Packaging Project" template.

This app is companion app that get installed from the main app which is a WinUI3 application. The code to install/updates resides in a separate class library. This class library is referenced in the main app.

It works when I reference this class library in a console project and call the code that eventually calls PackageManager.AddPackageAsync.