You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
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
Description
System.InvalidOperationException : 'CoreWebView2 members cannot be accessed after the WebView2 control is disposed
But WebView2 is not disposed
Version
Microsoft.Web.WebView2 1.0.1133-prerelease
Microsoft.Web.WebView2.DevToolsProtocolExtension 1.0.824
Framework: WinForms
OS: Win10
Repro Steps
private async void CopieWebBitmap()
MemoryStream ms = new MemoryStream();
await webBrowser1.CoreWebView2.CapturePreviewAsync(CoreWebView2CapturePreviewImageFormat.Jpeg, ms);
Global.xbrowserImage = new Bitmap(ms);
ms.Close();
ms.Dispose();
private void webBrowser1_CoreWebView2InitializationCompleted(object sender, Microsoft.Web.WebView2.Core.CoreWebView2InitializationCompletedEventArgs e)
CopieWebBitmap();
Screenshots
Additional context
AB#37874270
@Stumec Thanks for the bug report! Does this happen on the CapturePreviewAsync
line or somewhere else in the provided code? I wonder if it's related to being called in InitializationCompleted
... What happens if you move that call somewhere else, like in response to a button click or NavigationCompleted
?
CopieWebBitmap
is an async call that isn't being awaited, so the InitializationCompleted event is returning right away. If you had code that quickly spun up a WebView2 and then shut it down without waiting for CopieWebBitmap
to complete, then that might be why you are seeing it. Do you have such code, or is the WebView2 control created and then kept around for a long time/past the screenshot capture?