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

Visual Studio crashes on WebView2 dispose when hosted in multiple tool windows #816

Closed
priyasgs opened this issue Jan 13, 2021 · 13 comments
Closed
Labels
tracked We are tracking this work internally.

Comments

@priyasgs
Copy link

priyasgs commented Jan 13, 2021

I have a Visual Studio 2015 extension with a tool window that hosts WebView2. User can open multiple instances of the same, and hence I dispose the underlying WebView2 when the tool window is closed. In case an editor is open when the last such tool window is closed, I see a crash on WebView2.Dispose():

System.Runtime.InteropServices.COMException was unhandled
ErrorCode=-2147019873
HResult=-2147019873
Message=The group or resource is not in the correct state to perform the requested operation. (Exception from HRESULT: 0x8007139F)
Source=Microsoft.Web.WebView2.Core
StackTrace:
at Microsoft.Web.WebView2.Core.Raw.ICoreWebView2Controller.MoveFocus(COREWEBVIEW2_MOVE_FOCUS_REASON reason)
at Microsoft.Web.WebView2.Core.CoreWebView2Controller.MoveFocus(CoreWebView2MoveFocusReason reason)
at Microsoft.Web.WebView2.Wpf.WebView2.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at System.Windows.Interop.HwndHost.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
InnerException:

I saw a similar issue at #333 (comment)

I am attaching a sample with the scenario I described:
EdgeDisposeCrash.zip

Here are the exact steps to reproduce the problem with the sample

  1. Open the attached solution in Visual Studio 2015
  2. Build and run launches Visual Studio 2015 Experimental instance
  3. Open any text file
  4. From View->Other Windows, open EdgeDisposeCrashToolWindow
  5. Open another tool window using step 4
  6. Close tool window 2, followed by tool window 1

Visual Studio crashes. Uncomment the following 2 lines in the tool window's Dispose method:
//var window = dte.ActiveWindow;
//window.Activate();

Try the same steps, this time there is no crash. What am I doing wrong? There are other hosting scenarios I plan to implement with WebView2, and I cannot apply the same workaround in each such place. What is the way out?

AB#31402308

@champnic champnic added the tracked We are tracking this work internally. label Jan 20, 2021
@champnic
Copy link
Member

Thanks for the bug report - I've opened it on our backlog.

@champnic
Copy link
Member

This should be fixed in the latest 1.0.790-prerelease SDK package. Thanks!

@priyasgs
Copy link
Author

priyasgs commented Mar 5, 2021

This doesn't seem to be fixed in the latest runtime v89.0.774.45
When is the fix expected? Should I wait for the next stable SDK release?

@champnic
Copy link
Member

champnic commented Mar 6, 2021

@priyasgs Which SDK version are you using? The fix doesn't depend on a specific runtime, just the latest 1.0.790-prerelease SDK package.

@priyasgs
Copy link
Author

priyasgs commented Mar 9, 2021

Not fixed in the latest stable SDK release 1.0.774.44

@champnic
Copy link
Member

@priyasgs Have you been able to try it using the 1.0.790-prerelease SDK? It was fixed in version 789, so I wouldn't expect the 1.0.774.44 release to have the fix working.

@priyasgs
Copy link
Author

@champnic no I haven't. I can try that, and then wait for the next stable release to include the fix so I can ship it as part of our product.

@aks1008
Copy link

aks1008 commented Apr 9, 2021

@priyasgs - did issue got resolved for you?

I am also getting same error while trying to close the WPF application using X (close) icon. This error is causing when I am trying to dispose webView2. I might be doing some very common mistake.... but not able to identify why following error is coming.

OS: Win 10
WebView2 Version: 1.0.774.44

Code causing error:
if (previewBrowser != null) { previewBrowser.Dispose(); }

Steps to reproduce:

  1. Open PDF and try to close WPF app using X icon on top, it works fine.
  2. Open PDF file and draw line using editing option and close WPF app using X icon, it crashes host application also

One more observation from my end:

  • If I try to edit PDF, suppose try to draw line using pen pointer and then click on any other component in WPF application [outside of WebView] and then click on X (close icon for WPF application), it just work fine.
  • Here I am try to shift focus from WebView to WPF application as my error stack suggested something about focus and it is as below:

Description: The process was terminated due to an unhandled exception.
Exception Info: System.Runtime.InteropServices.COMException
at Microsoft.Web.WebView2.Core.Raw.ICoreWebView2Controller.MoveFocus(Microsoft.Web.WebView2.Core.Raw.COREWEBVIEW2_MOVE_FOCUS_REASON)
at Microsoft.Web.WebView2.Core.CoreWebView2Controller.MoveFocus(Microsoft.Web.WebView2.Core.CoreWebView2MoveFocusReason)
at Microsoft.Web.WebView2.Wpf.WebView2.WndProc(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
at System.Windows.Interop.HwndHost.SubclassWndProc(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(System.Object)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)
at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority, System.TimeSpan, System.Delegate, System.Object, Int32)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr, Int32, IntPtr, IntPtr)

@aks1008
Copy link

aks1008 commented Apr 9, 2021

@priyasgs - this issue has been resolved by updating webView2 version to 1.0.824-prerelease.

Thanks everyone!!

@aks1008
Copy link

aks1008 commented Apr 12, 2021

@champnic - as mentioned above the issue has been fixed in 1.0.824- prerelease.

But as per Microsoft documentation we should not use prerelease for production environment.
https://docs.microsoft.com/en-us/microsoft-edge/webview2/concepts/versioning

I am using this.focus() as work around for above mentioned error for our production product.

Can you please let me know when will be 1.0,824 will be stable version? I have tried to find in road map link, but no luck.
thanks in advance

@champnic
Copy link
Member

Typically the code in a prerelease package will be in the following release package, usually 6 weeks later.

@priyasgs
Copy link
Author

I can confirm the original issue I saw is now fixed in the latest stable 1.0.818.41 release. I don't need to workaround the focus issue anymore.

@champnic
Copy link
Member

@priyasgs Thanks for confirming!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tracked We are tracking this work internally.
Projects
None yet
Development

No branches or pull requests

3 participants