MicrosoftDocs / msix-docs

repository for msix content
Creative Commons Attribution 4.0 International
59 stars 114 forks source link

How to diagnose SEHException from AddPackageByAppInstallerFileAsync #256

Open yowl opened 3 years ago

yowl commented 3 years ago

Hi,

I've an Appx installed application from outside of the store and I want to trigger an update, when one is found. However AddPackageByAppInstallerFileAsync is throwing a SEHException:

Exception:
Type:System.Runtime.InteropServices.SEHException
Message:External component has thrown an exception.
Stack:
   at Windows.Management.Deployment.PackageManager.AddPackageByAppInstallerFileAsync(Uri appInstallerFileUri, AddPackageByAppInstallerOptions options, PackageVolume targetVolume)

How can I diagnose that?

I have the capability:

    <rescap:Capability Name="packageManagement" />
yowl commented 3 years ago

Bit more info from the event log AppxPackagingOM. There are 2 events

THis warning: '' 'App manifest validation warning: Declared namespace http://schemas.microsoft.com/developer/appx/2015/build is inapplicable, it will be ignored during manifest processing. '''

and this Information

The streaming reader was created successfully for app package b90d235c-ba69-42d6-8f61-7ec79035b0f2_1.0.27.72_x86__g5440y1v6mj70.

But no errors

dianmsft commented 3 years ago

Did you check the appxdeploymentserver event logs ? Those would be a good place to look to see what's going on.

Links to documentation: https://docs.microsoft.com/en-us/windows/win32/appxpkg/troubleshooting?context=/windows/msix/render

yowl commented 3 years ago

Yes, as per https://github.com/MicrosoftDocs/msix-docs/issues/256#issuecomment-912756019

dianmsft commented 3 years ago

Let me clarify, there are two logs: AppxPackagingOM > Microsoft-Windows-AppxPackaging/Operational AND AppXDeployment-Server > Microsoft-Windows-AppXDeploymentServer/Operational. I'm referring to AppXDeployment-Server

yowl commented 3 years ago

Just to confirm I did another test and no entries are present in Restricted and nothing for the time of the call in Operational

yowl commented 3 years ago

THe code for this is

try
            {
                // Get the current app's package for the current user.
                PackageManager pm = new PackageManager();
                Package package = pm.FindPackageForUser(string.Empty, Package.Current.Id.FullName);
                SetStatus($"Package found {package.DisplayName}, checking for update");
                PackageUpdateAvailabilityResult result = await package.CheckUpdateAvailabilityAsync();
                switch (result.Availability)
                {
                    case PackageUpdateAvailability.Available:
                    case PackageUpdateAvailability.Required:
                        SetStatus(result.Availability == PackageUpdateAvailability.Available ? "Update available, please restart." : "Update required, please restart");
                        //Queue up the update and close the current instance
                        try
                        {
                            await pm.RequestAddPackageByAppInstallerFileAsync(
                                new Uri(ConfigurationManager.AppSettings["installUri"]),
                                AddPackageByAppInstallerOptions.None, null);
                        }
                        catch (Exception e)
                        {
                            ErrorNotifier.NotifyError("failed to request update (RequestAddPackageByAppInstallerFileAsync) for installUri " + ConfigurationManager.AppSettings["installUri"] 
                                , "Name:{vol?.Name}" + Environment.NewLine + ExceptionHelper.GetErrorText(e), LoginContext.Current, ErrorNotifier.MailWcfServiceClient);
                            SetStatus("Update available, please restart.  " + Environment.NewLine + e);
                        }
                        break;
                    case PackageUpdateAvailability.NoUpdates:
                        SetStatus("No updates");
                        break;
                    case PackageUpdateAvailability.Unknown:
                        SetStatus("Unknown");
                        break;
                    default:
                        SetStatus("Other");
                        break;
                }

An update is detected, result.Availability == PackageUpdateAvailability.Available

yowl commented 3 years ago

Let me clarify, there are two logs: AppxPackagingOM > Microsoft-Windows-AppxPackaging/Operational AND AppXDeployment-Server > Microsoft-Windows-AppXDeploymentServer/Operational. I'm referring to AppXDeployment-Server

Thank you, I checked the AppXDeployment-Server and the Operational log has nothing for the time of the call.

dianmsft commented 3 years ago

Are any logs available? Maybe try installing through PowerShell and seeing if there’s different behavior?

yowl commented 3 years ago

Install and the built in automatic update works fine though, its the programmatic update that fails. The programmatic update is to save 2 restarts. Imagine you have the app open and an update is deployed. Next time you restart that update is picked up by the built in process but not applied (resources are in use etc.). So the update is applied on the next restart - hence 2 restarts. The programmatic update is to avoid that. A thread watches every so often for an update, if it detects one it schedules the update and informs the user to restart. This is the behaviour that I understand RequestAddPackageByAppInstallerFileAsync is for, but is not working due to the SEHException.

yowl commented 3 years ago

Maybe try installing through PowerShell and seeing if there’s different behavior?

Thanks, I had a think about this, but couldn't see what the equivalent powershell would be for RequestAddPackageByAppInstallerFileAsync when the app is installed and running. Do you know?

mikehearn commented 2 years ago

Is this problem still existing? If so, SEHException has some properties that could be useful to diagnose. In particular the ErrorCode property might be informative.

matthew-northg commented 1 year ago

I'm having the exact same issue with code almost identical to @yowl's.

Here's the stack trace if that's helpful to anyone: System.Runtime.InteropServices.SEHException (0x80004005): External component has thrown an exception. at ABI.Windows.Management.Deployment.IPackageManager6Methods.RequestAddPackageByAppInstallerFileAsync(IObjectReference _obj, Uri appInstallerFileUri, AddPackageByAppInstallerOptions options, PackageVolume targetVolume) at Windows.Management.Deployment.PackageManager.RequestAddPackageByAppInstallerFileAsync(Uri appInstallerFileUri, AddPackageByAppInstallerOptions options, PackageVolume targetVolume) at [REDACTED].Services.AutomaticUpdateService.checkForAppInstallerUpdatesAsync(CancellationToken cancellationToken) at [REDACTED].Services.AutomaticUpdateService.process(CancellationToken cancellationToken)

Was anyone able to get to the bottom of the issue and resolve it?