MicrosoftEdge / WebView2Feedback

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

Unhandled exception in Microsoft.Web.WebView2.Wpf.WebView2.Dispose #3752

Open rozeboosje opened 1 year ago

rozeboosje commented 1 year ago

As this happened once on a client machine, all I can give you is the error as it was logged in the Event Viewer: Description: The process was terminated due to an unhandled exception. Exception Info: System.InvalidCastException at System.StubHelpers.StubHelpers.GetCOMIPFromRCW(System.Object, IntPtr, IntPtr ByRef, Boolean ByRef) at Microsoft.Web.WebView2.Core.Raw.ICoreWebView2Controller.get_CoreWebView2() at Microsoft.Web.WebView2.Core.CoreWebView2Controller.get_CoreWebView2() at Microsoft.Web.WebView2.Wpf.WebView2.Uninitialize(Boolean) at Microsoft.Web.WebView2.Wpf.WebView2.Dispose(Boolean) at System.Windows.Interop.HwndHost.Finalize()

The next message in the event viewer then reads: Faulting application name: our application here, time stamp: 0x64ef3c24 Faulting module name: KERNELBASE.dll, version: 6.3.9600.20772, time stamp: 0x639ac196 Exception code: 0xe0434352 Fault offset: 0x000000000000450c Faulting process ID: 0x27938 Faulting application start time: 0x01d9dbe18e73726f Faulting application path: path to our application Faulting module path: C:\Windows\system32\KERNELBASE.dll Report ID: 223dcf3a-47e4-11ee-84bb-40e2303bce86 Faulting package full name: Faulting package-relative application ID:

Version SDK: 10.0.22621.755 Runtime: 109.0.1518.115 Framework: .NET Framework 4.8, WPF OS: Windows 8.1 Pro

Please note that I have Runtime 116.0.1938.62 on my own machine and I did notice an occasional error being raised during debugging but it never caused our application to crash so I never paid a lot of attention to it. Sorry. My own machine is Windows 11 22H2

Regression Was this working before but has regressed? Unsure If yes, what version did this last work on? Unsure

Repro Steps Unsure. User stated the application just "crashed"

Not available

AB#46359270

LiangTheDev commented 1 year ago

@rozeboosje what is the WebView2 SDK version (the version of the nuget package got from https://www.nuget.org/packages/Microsoft.Web.WebView2)? I've created an internal tracking issue for this and see what we can repro/address it.

rozeboosje commented 1 year ago

@rozeboosje what is the WebView2 SDK version (the version of the nuget package got from https://www.nuget.org/packages/Microsoft.Web.WebView2)? I've created an internal tracking issue for this and see what we can repro/address it.

The nuGet version is 10.0.22621.755 which I think is the current one?

LiangTheDev commented 1 year ago

10.0.22621.755 is the Windows SDK version. WebView2 SDK version is something like 1.0.1938.49.

rozeboosje commented 1 year ago

10.0.22621.755 is the Windows SDK version. WebView2 SDK version is something like 1.0.1938.49.

Oops my bad.... I was looking at it cross eyed and ended up giving you the version for Microsoft.Windows.SDK.Contracts!

Microsoft.Web.WebView2 is 1.0.1938.49 alright.

ryanmolden commented 11 months ago

Folks internal to Microsoft can find dumps for this issue in the following Watson buckets

1603193249604093317 1286323913959092884 1563832971297480184 1171199957857181220 1166574664220614861

LiangTheDev commented 11 months ago

Thanks for the Watson buckets. We will look into them.

The call stack indicates that this is happening on finalizer worker thread and the WebView2 control has not been explicitly exposed before the finalizer. To mitigate the issue before we address the issue in WebView2 SDK, could you try to mitigate the issue by explicitly calling Dispose WebView2 controllers when we are done with them?

ryanmolden commented 11 months ago

I am not on the team that owns primary usage of the control in VS, but I have assigned the internal bug to them and linked this discussion.

drab0wl commented 11 months ago

@LiangTheDev @ryanmolden I'm investigating from the VS control side of things. The stacks shown in those Watsons do not include some stack data we have from our partners that show this is happening as a result of us explicitly calling WebView2.Dispose. This happens when using the WPF version of WebView2, so no access to the CoreWebView2Controller class, just the control itself. The telemetry they collected only goes as far as our Dispose method that calls yours, but not actually into the WebView2 code itself.

LiangTheDev commented 11 months ago

The stack in the first post shows that it is "System.Windows.Interop.HwndHost.Finalize()" that is calling Microsoft.Web.WebView2.Wpf.WebView2.Dispose, and it is consistent with the stack from Watson. From Watson stacks, there is a case where Dispose is explicitly called for WinForms WebView2 Controller.