Skip to content
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

[Problem/Bug]: Exception on Dispose() of WPF WebView2 control #4263

Open
imranp23 opened this issue Dec 28, 2023 · 5 comments
Open

[Problem/Bug]: Exception on Dispose() of WPF WebView2 control #4263

imranp23 opened this issue Dec 28, 2023 · 5 comments
Assignees
Labels
bug Something isn't working

Comments

@imranp23
Copy link

What happened?

I am using Microsoft.Web.WebView2.Wpf.WebView2 object as a static member of a singleton class which is used across application.
In Xaml window, I am adding this object to UI Grid as children at runtime whenever I need it and removing it from the same Grid on closing of the window.
While closing the application this singleton class is disposing the WebView2 object which is invoked on UI thread.

Still facing the Exception as below,

System.InvalidCastException: Unable to cast COM object of type 'System.__ComObject' to interface type 'Microsoft.Web.WebView2.Core.Raw.ICoreWebView2Controller'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{4D00C0D1-9434-4EB6-8078-8697A560334F}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
at System.StubHelpers.StubHelpers.GetCOMIPFromRCW(Object objSrc, IntPtr pCPCMD, IntPtr& ppTarget, Boolean& pfNeedsRelease)
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 browserCrashed)
at Microsoft.Web.WebView2.Wpf.WebView2.Dispose(Boolean disposing)
at System.Windows.Interop.HwndHost.Finalize()

Importance

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

Runtime Channel

Stable release (WebView2 Runtime)

Runtime Version

120.0.2210.91

SDK Version

1.0.1518.46

Framework

WPF

Operating System

Windows 10, Windows 11

OS Version

No response

Repro steps

Calling WebView2.Dispose() at end of application.

Repros in Edge Browser

Not Applicable

Regression

Don't know

Last working version (if regression)

No response

@imranp23 imranp23 added the bug Something isn't working label Dec 28, 2023
@adakaraju
Copy link

I am also facing same issue which is leading to a crash.

Can you please look into this ASAP.

@champnic
Copy link
Member

Hey @imranp23 / @adakaraju - Do either of you have a sample app that reproduces this issue that we could take a look at?

In the past, the issue with the Finalizer doing the WebView2 cleanup is that it could happen on a background thread, rather than the thread the WebView2 was created on.

@pushkin-
Copy link

pushkin- commented Apr 8, 2024

@champnic I will look into getting a minimal example, but in the meantime, I get a similar issue:

System.NotImplementedException: 'Unable to cast to Microsoft.Web.WebView2.Core.Raw.ICoreWebView2_13.
This may happen if you are using an interface not supported by the version of the WebView2 Runtime you are using.

I am just accessing CoreWebView2::Profile in my code (inside of a Task if it matters). I don't think anything should be disposed at this point.

I can access it earlier - like when I'm navigating the webview2.

@champnic
Copy link
Member

champnic commented Apr 8, 2024

WebView2 should only be accessed by a single thread - is that task running on the same thread that created the WebView2?

@pushkin-
Copy link

pushkin- commented Apr 8, 2024

@champnic oh probably not. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants