When the desktop bridge application uses the update API, disconnecting the network will cause the app to crash

0

Using StoreContext.CanSilentlyDownloadStorePackageUpdates when the network is disconnected will cause the app to crash, and I try to use Try-Catch to fail to catch this exception. In addition, when I use StoreContext.TrySilentDownloadStorePackageUpdatesAsync to download the update package, disconnecting the network at this time will also cause the APP to crash too.

Code snippet:

[System.Runtime.ExceptionServices.HandleProcessCorruptedStateExceptions]
public bool CanSilentlyUpdate()
{
    try
    {
        //There will be an error:
        //    System.AccessViolationException :“Attempted to read or write protected memory. 
        //    This is often an indication that other memory is corrupt.”
        return StoreContext.GetDefault().CanSilentlyDownloadStorePackageUpdates;
    }
    catch (Exception ex)
    {
        Debug.WriteLine(ex);
        return false;
    }
}

The following is the error log in Event Viewer:

Eventlog 1: Application: MyApp.exe Framework Version: v4.0.30319 Description: The process was terminated due to an unhandled exception. Exception Info: System.AccessViolationException at Windows.Services.Store.StoreContext.get_CanSilentlyDownloadStorePackageUpdates()

Eventlog 2: Faulting application name: MyApp.exe, version: 1.0.0.0, time stamp: 0x96223b82 Faulting module name: Windows.ApplicationModel.Store.dll, version: 10.0.19041.329, time stamp: 0x92fa3e59 Exception code: 0xc0000005 Fault offset: 0x0009fcb0 Faulting process id: 0x6d0c Faulting application start time: 0x01d6511c5d86de48 Faulting application path: C:\Program Files\WindowsApps\MyApp\MyApp.exe Faulting module path: C:\Windows\System32\Windows.ApplicationModel.Store.dll Report Id: d67098d6-39c7-4a02-a837-b523821c9ca2 Faulting package full name: MyApp Faulting package-relative application ID: App

Eventlog 3: Application: MyApp.exe Framework Version: v4.0.30319 Description: The process was terminated due to an unhandled exception. Exception Info: exception code c0000005, exception address 7947FCB0 Stack:

Eventlog 4: Faulting application name: MyApp.exe, version: 1.0.0.0, time stamp: 0x96223b82 Faulting module name: Windows.ApplicationModel.Store.dll, version: 10.0.19041.329, time stamp: 0x92fa3e59 Exception code: 0xc0000005 Fault offset: 0x0009fcb0 Faulting process id: 0x36a0 Faulting application start time: 0x01d65131af3782e2 Faulting application path: C:\Program Files\WindowsApps\MyApp\MyApp.exe Faulting module path: C:\Windows\System32\Windows.ApplicationModel.Store.dll Report Id: 4a027389-345c-4f16-a605-276f2774c768 Faulting package full name: MyApp Faulting package-relative application ID: App

This kind of exception seems to be unable to be caught using managed code, what should I do?

c#
uwp
desktop-bridge
asked on Stack Overflow Jul 3, 2020 by Victor • edited Jul 6, 2020 by Victor

1 Answer

1

After discussing with other engineers, it looks like there is no other way to handle it. This method should be running in the background so that you could not catch it in the UI thread. It essentially bypasses any chance dev has at handling the exception.

Our suggestion is that you need to check the network before calling this method and give a tip when calling this method to tell the user to keep network connection. And you could try to subscribe to the NetworkInformation.NetworkStatusChanged Event in your app.

answered on Stack Overflow Jul 13, 2020 by Roy Li - MSFT

User contributions licensed under CC BY-SA 3.0