MicrosoftEdge / WebView2Feedback

Feedback and discussions about Microsoft Edge WebView2
https://aka.ms/webview2
452 stars 55 forks source link

[Problem/Bug]: winrt::hresult_error on app closing when WebView2 control presents in a WinUI3 app that is packaged with a separate WAP project #4814

Closed aries-zhang closed 1 month ago

aries-zhang commented 1 month ago

What happened?

With the following minimal XAML code in a skeleton WinUI 3 app created with the VisualStudio template "Blank App, Packaged with Windows Application Package Project (WinUI 3 in Desktop)":

<Grid>
    <WebView2 Source="https://bing.com"/>
</Grid>

The app crashes with the following exception when it is closed: image

The exception does not occur with the same code in a project created with the template "Blank App, Packaged (WinUI 3 in Desktop)".

Please see the code in this repo: https://github.com/aries-zhang/winui3-adventure/tree/main/closing-exception-with-webview2

PackagedWithSameProject is for the 2nd scenario where the app does not crash on closing. PackagedWithSeparateWapProject is for the 1st scenario where the issue repros.

Importance

Important. My app's user experience is significantly compromised.

Runtime Channel

Stable release (WebView2 Runtime)

Runtime Version

128.0.2739.79

SDK Version

No response

Framework

WinUI3/WinAppSDK

Operating System

Windows 11

OS Version

23H2

Repro steps

  1. Create a new project in Visual Studio (2022) with the template "Blank App, Packaged with Windows Application Package Project (WinUI 3 in Desktop)".

  2. Open MainWindow.xaml in the new project, remove the <StackPanel ...> ... </StackPanel> code, add the following code:

    <Grid>
    <WebView2 Source="https://bing.com"/>
    </Grid>
  3. Run the app in Visual Studio with "Local Machine". The app should start and load Bing.com.

  4. Close the app, the following exception occurs: image

Exception thrown at 0x00007FFDDAFAFABC (KernelBase.dll) in App8.exe: WinRT originate error - 0x8007139F : 'The group or resource is not in the correct state to perform the requested operation.'.
Exception thrown at 0x00007FFDDAFAFABC in App8.exe: Microsoft C++ exception: winrt::hresult_error at memory location 0x000000234417D190.

Repros in Edge Browser

No, issue does not reproduce in the corresponding Edge version

Regression

No, this never worked

Last working version (if regression)

No response

github-actions[bot] commented 1 month ago

Hi, @aries-zhang!

It seems that your issue contains the word "crash". If you have not already, could you attach a crash dump as a comment?

WV2 crash dumps are located in a subfolder of the app's user data folder (UDF): <UDF>\EBWebView\Crashpad\reports\. By default, the user data folder is created in the app's folder with a name like <App Exe Name>.exe.WebView2. Refer to Crash Diagnostics for more information.

Thank you for your cooperation!

aries-zhang commented 1 month ago

No file exists under <UDF>\EBWebView\Crashpad\reports\.

oggy22 commented 1 month ago

Hi @aries-zhang , can you please provide the SDK version number in the bug template?

aries-zhang commented 1 month ago

Hi @oggy22 if you mean WinAppSDK version number it is 1.6.240829007 (project link). There is no WebView2 SDK involved in this case since it's just a <WebView2 /> element in XAML.

aries-zhang commented 1 month ago

Please see this issue in WinUI 3 repo for workaround: https://github.com/microsoft/microsoft-ui-xaml/issues/7632.

Explicitly disposing WebView2 by calling TheWebView2Instance.Close() when app closes fixes the issue.