0

I am using the AddPackageByAppInstallerFileAsync method on several UWP apps. It has worked on all of the apps except recently for one of the apps. I get a "Access is denied. (Exception from HRESULT: 0x80070005)" exception.

https://learn.microsoft.com/en-us/uwp/api/windows.management.deployment.packagemanager.addpackagebyappinstallerfileasync?view=winrt-26100

I have tried uninstalling and reinstalling the app. Running the .appinstaller works just fine. Updating using the .appinstaller works just fine.

AddPackageByAppInstallerFileAsync just stopped working recently for this particular app. What causes this issue?

 await pm.AddPackageByAppInstallerFileAsync(
                new Uri("https://url/app.appinstaller"),
                AddPackageByAppInstallerOptions.ForceTargetAppShutdown,
                pm.GetDefaultPackageVolume());

2 Answers 2

0

The 0x80070005 (E_ACCESSDENIED) error in your usage of AddPackageByAppInstallerFileAsync usually indicates a permissions or access issue at some level. Since this started happening only for one app and recently, and appinstaller works fine manually, the problem is likely environmental or specific to that app’s configuration. Here are the most common causes and potential solutions:

1. App Installer File Permissions

Even though the .appinstaller file works manually, the context in which your code calls it may have different permissions.

Check:

  • Is the URL HTTPS with a valid certificate?

  • Is access to the .appinstaller file gated by headers, tokens, or authentication?

  • Can the app be accessed without user interaction (e.g., no prompt)?

Fix:

  • Try accessing the URL from the same account/environment where the UWP code runs.

  • Ensure app.appinstaller and referenced .msix/.appxbundle files have public or proper access permissions.

2. App is Running or Cannot Be Shut Down

ForceTargetAppShutdown tries to close the target app, but if the system cannot do this (e.g., it's running under another user session or has background tasks), it might fail.

Fix:

  • Ensure the app is not running in background (check via Task Manager or UWP TaskHost).

  • Try removing ForceTargetAppShutdown and see if error changes.

3. Package Identity Mismatch or Corruption

If the identity (Publisher, Version, Package Name) is mismatched between the installed version and the one being installed, it could block installation.

Fix:

  • Fully uninstall the app (Get-AppxPackage in PowerShell → Remove-AppxPackage).

  • Check for leftover entries in registry or %ProgramFiles%\WindowsApps.

4. Capabilities or Restricted Declarations

Recent updates or changes in manifest (e.g., capabilities like runFullTrust, restricted API usage) may cause access denial, especially if not signed with proper certificates.

Fix:

  • Check the manifest for new capabilities or restricted APIs.

  • If added recently, ensure you're using a properly signed certificate (trusted by the machine).

5. Package Volume Issues

If the target volume (from GetDefaultPackageVolume()) is no longer valid or writable, this can result in Access Denied.

Fix:

  • Try omitting the packageVolume argument to let the system choose default.

    await pm.AddPackageByAppInstallerFileAsync(     new Uri("https://url/app.appinstaller"),     AddPackageByAppInstallerOptions.ForceTargetAppShutdown);
    
Sign up to request clarification or add additional context in comments.

2 Comments

To add, I also get this exception even when debugging in VS. In contrast, the other very similar apps do not crash on the AddPackageByAppInstallerFileAsync line. the packageVolumen argument seems to be required so I can't leave it blank. I passed null with the same result. I also tried AddPackageByAppInstallerOptions.None with the same result.
I ended up separating var vol = pm.GetDefaultPackageVolume(); and it's crashing on this line now.
0

I inadvertently commented this in the manifest:

<rescap:Capability Name="packageManagement" />

Uncommented and now it works again.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.