UWP with WebView2 won't launch or uninstall

Jack Lee 6 Reputation points
2022-01-14T20:21:22.433+00:00

Description
If I open a UWP app for about 10 minutes, after I close the app, I won't be able to open it again. The app will stuck at the logo screen. In term of app lifecycle, I don't think the app is started at all. There isn't any process running in the background, and there isn't any error prompted.

Sometimes, after the first or second times this behavior has shown up, I can still close the app while it stuck, then try to launch it again and it will launch properly. However, after the third or forth time, the app will always stuck at the logo screen and I won't be able to launch or uninstall it until I have restarted my computer. The only way for this behavior to not show up is to always run the app through visual studio debugger session.

The app I have written only has a WebView2 control. I have tried to import WebView2 into a UWP app with WinUI2 and WinUI3. I also tried installed through VS studio, sideload installation, debug build and release build. They all have this issue.

There isn't any error log shown in the Event Viewer. I have tried to uninstall the app with command line Remove-AppxPackage, the process is initialized but stuck initialized. If I installed through visual studio, I won't be able to launch with visual studio. If I installed through sideload build, I won't be able to reinstall with the installation wizard.

Version
SDK: Microsoft.WindowsAppSDK (1.0.0-experimental1) or Microsoft.UI.Xaml (2.8.0-prerelease.210927001)
Runtime: Dev 99.0.1131.3
Framework: UWP
OS: Win10

Repro Steps

Create UWP with WebView2 package through WinUI3 or WinUI2
Install the app through Visual Studio 19 or sideload build
Open the app through Start Menu, and let the app run for at least 10 minutes
Close the app, and try to launch it gain. If app launch successfully, repeat step 3.
Expected:
The app will launch.
Actual:
Stuck at logo screen, and closes itself after a while. Cannot uninstall app.

Screenshots
Here is the logo screen I am talking about:

165187-image.png

Developer technologies | Universal Windows Platform (UWP)
{count} vote

1 answer

Sort by: Most helpful
  1. JuRei 1 Reputation point
    2022-02-09T15:18:39.827+00:00

    I am experiencing the very same issue in my UWP app. I tried hard, but unfortunately I cannot reproduce the problem in a small example app and I cannot share my actual app with you.
    Reproduction steps are the same as JackLee's, but it only takes 2 minutes of waiting instead of 10. I am navigating to the WebView2, staring at my screen (doing nothing) for 2 minutes and closing the app.

    I am using Microsoft.UI.Xaml 2.8.0-prerelease.220118001

    • Using an "old" WebView, the problem never arose. It started when I replaced the WebView by WebView2.
    • You have to navigate to the WebView2. Just opening the app and not navigating to the WebView2 + wait for 2 min is not enough.
    • If you just open and close the app quickly (and always navigate to WebView2, closing the app after a couple of seconds), it doesn't happen
    • It happens both when installed via Visual Studio and when built and installed with the msixbundle.
    • After restarting the PC, the app can be started / uninstalled again
    • If it happens you can start the app as many times as you want, you will not get past the splash screen
    • When it happens you can't uninstall the app (without restarting the PC first).
    • If it occurs while debugging in Visual Studio, you can't exit the Visual Studio debugger at all (when you click on the red square, Visual Studio gets stuck)

    While I can't share my source code with you, I can try to explain what I did:

    • The WebView2 is embedded in a Grid, which is itself embedded in a UserControl.
    • I am using SetVirtualHostNameToFolderMapping to map a folder within the LocalState folder to "viewer.local"
    • I am navigating to an html file that the app placed in the folder. All of this works well and exactly as intended.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.