-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
App Crash on WebView2 background finalize #955
Comments
What thread do you dispose the WebView2 instance on? |
It is on the UI thread when I call .Dispose(), but it seems like when the Finalize() rolls through it is on a different thread? Here are the two places I dispose of the web control -- pardon the VB, it's an old app :) --
The other one is for when a window with a browser closes:
|
Based on that stack it looks like when the finalizer is calling Dispose() from the background thread Dispose() hasn't yet been called on the WebView2. Can you put breakpoints on where you are disposing of the WebView2 and verify that it's getting called before the finalizer? |
I checked it and I do call Dispose() from the ProcessFailedHandler, but the _browser.Dispose() throws with: So, I'm guessing the .Dispose() never actually happens, so the Finalizer picks it up later and then fails and it crashes my entire app. I can't figure out any way to prevent this app crash. I believe this all stems from the original problem of handling the process crashes: |
Ya that seems related to me. We have a fix for #774 that improves this experience and I think it should fix this as well. It should make Dispose() not cause an exception when called after the browser has crashed. I'll respond to this thread when the fix is available to try in the next prerelease package. |
Do you have a timeline on this? If I keep a list of references to my crashed WebView2 objects that error in disposal, would that prevent the Finalizer from running and crashing the app? Until your fix goes live. |
The next prerelease package (that will include this fix) will go out soon, within the next week or two. That workaround sounds reasonable to try. |
This should be fixed in the 1.0.824-prerelease SDK. Please give it a try and let us know if you run into any further issues. Thanks! |
This seems to still be the case in 1.0.1774.30 I can call a dispose on Unloaded and then quit the application and it works fine but just closing the app or calling an Application.Exit() with an Active WPF Window Open (and a webview active) causes the application to immediately crash out Exception Occured - Unhandled Exception I can't capture the Finalize method (by design) to gracefully dispose the control. |
It seems that the error still occurs with the current version: 1.0.2903.40 Provider: .NET Runtime Framework: .NET Framework 4.8, WPF Calling Dispose() on Unloaded works but it shouldn't be necessary, why do we need manually to Dispose this? |
Looks like they closed this so it would have to be re-opened as a new bug. |
Description
I have a WPF app using .NET Framework 4.7.2, that contains multiple WebView2 instances. Intermittently, we get an app crash during the finalize of the WebView2 control
Here is the error from Windows Event Viewer.
Description: The process was terminated due to an unhandled exception.
Exception Info: System.InvalidOperationException
at System.Windows.Threading.Dispatcher.VerifyAccess()
at Microsoft.Web.WebView2.Wpf.WebView2.get_CoreWebView2()
at Microsoft.Web.WebView2.Wpf.WebView2.Dispose(Boolean)
at System.Windows.Interop.HwndHost.Finalize()
I can't find any way to prevent this from happening.
Version
WebView2 1.0.721-prerelease
.NET Framework 4.7.2
Repro Steps
I believe it eventually happens after a user opens a window with a WebView2 and then closes it. We dispose of the WebView2 instance, but a little while later, the app crashes (during the finalize process).
Screenshots
Additional context
AB#31292515
The text was updated successfully, but these errors were encountered: