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:
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:
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:
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);