MicrosoftEdge / WebView2Feedback

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

[Problem/Bug]: WebView2 crashes entire application after opening modal window in event handler #4734

Open mo4379 opened 3 months ago

mo4379 commented 3 months ago

What happened?

Opening a MessageBox in WebView event handler causes the application to crash after 30 seconds. I know that this is not recommended here: https://learn.microsoft.com/en-us/microsoft-edge/webview2/concepts/threading-model#reentrancy and to use SynchronizationContext instead. But crash is also not a correct behavior.

Importance

Moderate. My app's user experience is affected, but still usable.

Runtime Channel

Stable release (WebView2 Runtime), Prerelease (Edge Canary/Dev/Beta)

Runtime Version

126.0.2592.113

SDK Version

1.0.2592.51

Framework

Winforms

Operating System

Windows 10

OS Version

19045.4651

Repro steps

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 3 months ago

Hi, @mo4379!

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!

mo4379 commented 3 months ago

There is nothing in the reports directory. The event CoreWebView2.ProcessFailed is not firing.

Additional observation: the crash happens during debugging in Visual Studio, not when running exe directly.

mo4379 commented 3 months ago

The Visual Studio reports only this:

The thread '[Thread Destroyed]' (3856) has exited with code 0 (0x0). The thread '[Thread Destroyed]' (20960) has exited with code 0 (0x0). The thread '[Thread Destroyed]' (22844) has exited with code 0 (0x0). The thread '[Thread Destroyed]' (19180) has exited with code 0 (0x0). The program '[42228] WinFormsApp1.exe' has exited with code 2147483651 (0x80000003).

Event Viewer has this error:

Faulting application name: WinFormsApp1.exe, version: 1.0.0.0, time stamp: 0x65f90000 Faulting module name: EmbeddedBrowserWebView.dll, version: 126.0.2592.113, time stamp: 0x66980e99 Exception code: 0x80000003 Fault offset: 0x000000000039acbd Faulting process id: 0xa4f4 Faulting application start time: 0x01daea71ac4b3e35 Faulting application path: C:\data\source\repos\ProjectsVS2022\WinFormsApp1\WinFormsApp1\bin\Debug\net8.0-windows\WinFormsApp1.exe Faulting module path: C:\Program Files (x86)\Microsoft\EdgeWebView\Application\126.0.2592.113\EBWebView\x64\EmbeddedBrowserWebView.dll Report Id: fcc73558-f5a4-4335-b6e3-569c6041845a Faulting package full name: Faulting package-relative application ID:

Also there is some dump: crash.zip

Brentwatch2021 commented 3 months ago

Hi @mo4379

I am having a similar issue with regards to Message Box causing it to crash every time also at about 20 to 35 seconds after capturing the message box.

I also did not get any exception thrown

I enabled Native Code Debugger as Webview consumes from unmanaged code c++ etc besides .net 8 and I was able to hit an exception steps to enable:

go to project properties

under Debug tab check enable native code debugging and enable it this will allow you to debug unmanaged and maybe catch the exception?

mo4379 commented 3 months ago

After enabling native code debugging, I got this exception:

A breakpoint instruction (__debugbreak() statement or a similar call) was executed in WinFormsApp1.exe.

Callstack:

EmbeddedBrowserWebView.dll!00007ff8c4c1acbd() Unknown EmbeddedBrowserWebView.dll!00007ff8c494d163() Unknown EmbeddedBrowserWebView.dll!00007ff8c4b6e71c() Unknown EmbeddedBrowserWebView.dll!00007ff8c4b6e60c() Unknown EmbeddedBrowserWebView.dll!00007ff8c4a98e1f() Unknown user32.dll!00007ff94067ef5c() Unknown user32.dll!00007ff94067e684() Unknown user32.dll!00007ff94069eb31() Unknown user32.dll!00007ff94069e7a1() Unknown user32.dll!00007ff9406eb64b() Unknown user32.dll!00007ff9406e9f65() Unknown user32.dll!00007ff9406ead57() Unknown user32.dll!00007ff9406eadde() Unknown [Managed to Native Transition]
System.Windows.Forms.Primitives.dll!Windows.Win32.PInvoke.MessageBox(Windows.Win32.Foundation.HWND hWnd, Windows.Win32.Foundation.PCWSTR lpText, Windows.Win32.Foundation.PCWSTR lpCaption, Windows.Win32.UI.WindowsAndMessaging.MESSAGEBOX_STYLE uType) Line 25939 C# System.Windows.Forms.Primitives.dll!Windows.Win32.PInvoke.MessageBox(Windows.Win32.Foundation.HWND hWnd, string lpText, string lpCaption, Windows.Win32.UI.WindowsAndMessaging.MESSAGEBOX_STYLE uType) Line 25931 C# System.Windows.Forms.dll!System.Windows.Forms.MessageBox.ShowCore(System.Windows.Forms.IWin32Window owner, string text, string caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, System.Windows.Forms.MessageBoxDefaultButton defaultButton, System.Windows.Forms.MessageBoxOptions options, bool showHelp) Line 478 C# System.Windows.Forms.dll!System.Windows.Forms.MessageBox.Show(string text) Line 343 C# WinFormsApp1.dll!WinFormsApp1.Form1.Webview_NavigationCompleted(object sender, Microsoft.Web.WebView2.Core.CoreWebView2NavigationCompletedEventArgs e) Line 69 C# Microsoft.Web.WebView2.WinForms.dll!Microsoft.Web.WebView2.WinForms.WebView2.CoreWebView2_NavigationCompleted(object sender, Microsoft.Web.WebView2.Core.CoreWebView2NavigationCompletedEventArgs e) Unknown Microsoft.Web.WebView2.Core.dll!Microsoft.Web.WebView2.Core.CoreWebView2.OnNavigationCompleted(Microsoft.Web.WebView2.Core.CoreWebView2NavigationCompletedEventArgs args) Unknown Microsoft.Web.WebView2.Core.dll!Microsoft.Web.WebView2.Core.CoreWebView2NavigationCompletedEventHandler.Invoke(Microsoft.Web.WebView2.Core.Raw.ICoreWebView2 source, Microsoft.Web.WebView2.Core.Raw.ICoreWebView2NavigationCompletedEventArgs args) Unknown [Native to Managed Transition]
EmbeddedBrowserWebView.dll!00007ff8c4905c6f() Unknown EmbeddedBrowserWebView.dll!00007ff8c4905b2d() Unknown EmbeddedBrowserWebView.dll!00007ff8c496336e() Unknown EmbeddedBrowserWebView.dll!00007ff8c4bcaa4a() Unknown EmbeddedBrowserWebView.dll!00007ff8c49c45d7() Unknown EmbeddedBrowserWebView.dll!00007ff8c4b1864a() Unknown EmbeddedBrowserWebView.dll!00007ff8c4b18e03() Unknown EmbeddedBrowserWebView.dll!00007ff8c4b18d9a() Unknown EmbeddedBrowserWebView.dll!00007ff8c4b187f9() Unknown EmbeddedBrowserWebView.dll!00007ff8c4b1864a() Unknown EmbeddedBrowserWebView.dll!00007ff8c49b94d1() Unknown EmbeddedBrowserWebView.dll!00007ff8c49b97ff() Unknown EmbeddedBrowserWebView.dll!00007ff8c4a20c49() Unknown EmbeddedBrowserWebView.dll!00007ff8c4b13fcd() Unknown EmbeddedBrowserWebView.dll!00007ff8c4b13fcd() Unknown EmbeddedBrowserWebView.dll!00007ff8c4b178cf() Unknown EmbeddedBrowserWebView.dll!00007ff8c4b04114() Unknown EmbeddedBrowserWebView.dll!00007ff8c494da9e() Unknown EmbeddedBrowserWebView.dll!00007ff8c494d9c6() Unknown EmbeddedBrowserWebView.dll!00007ff8c494d16d() Unknown EmbeddedBrowserWebView.dll!00007ff8c4b6e71c() Unknown EmbeddedBrowserWebView.dll!00007ff8c4b6e60c() Unknown EmbeddedBrowserWebView.dll!00007ff8c4a98e1f() Unknown user32.dll!00007ff94067ef5c() Unknown user32.dll!00007ff94067e684() Unknown System.Windows.Forms.Primitives.dll!00007ff894f005a9() Unknown [Managed to Native Transition]
System.Windows.Forms.Primitives.dll!Windows.Win32.PInvoke.DispatchMessage(Windows.Win32.UI.WindowsAndMessaging.MSG lpMsg) C# System.Windows.Forms.dll!System.Windows.Forms.Application.ComponentManager.Microsoft.Office.IMsoComponentManager.FPushMessageLoop(nuint dwComponentID, Microsoft.Office.msoloop uReason, void pvLoopData) Line 290 C# System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Microsoft.Office.msoloop reason, System.Windows.Forms.ApplicationContext context) Line 1063 C# System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Microsoft.Office.msoloop reason, System.Windows.Forms.ApplicationContext context) Line 929 C# WinFormsApp1.dll!WinFormsApp1.Program.Main() Line 14 C# [Native to Managed Transition]
hostpolicy.dll!00007ff8f44d2b76() Unknown hostpolicy.dll!00007ff8f44d2e5c() Unknown hostpolicy.dll!00007ff8f44d379a() Unknown hostfxr.dll!00007ff8f510b5c9() Unknown hostfxr.dll!00007ff8f510e066() Unknown hostfxr.dll!00007ff8f51102ec() Unknown hostfxr.dll!00007ff8f510e644() Unknown hostfxr.dll!00007ff8f51085a0() Unknown WinFormsApp1.exe!00007ff65db5f998() Unknown WinFormsApp1.exe!00007ff65db5fda6() Unknown WinFormsApp1.exe!00007ff65db612e8() Unknown kernel32.dll!00007ff9408c7374() Unknown ntdll.dll!00007ff94257cc91() Unknown

After catching this exception I can now continue execution, and get this exception again after 30 seconds.