microsoft / microsoft/msix-packaging

UnauthorizedAccessException on PackageManager.AddPackageAsync

Open
#615 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Area-External Area-MSIX
Dominant language
C
Stars
1.1k
Forks
193
Avg merge
2h 16m
Merged PRs (30d)
2

Description

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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at UpdateTask.cs line 18 and Updater.cs line 35, where PackageManager.AddPackageAsync is called, and compare the class library's behavior when hosted by the console project versus the WinUI 3 application. Reproduce the deployment failure and inspect the MSIX package metadata and host context. Done means the cause of the access denial is identified and a verified resolution is documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
desktop, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.