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

Application crashes #333

Closed
fvanheeswijk opened this issue Jul 13, 2020 · 12 comments
Closed

Application crashes #333

fvanheeswijk opened this issue Jul 13, 2020 · 12 comments
Labels
bug Something isn't working

Comments

@fvanheeswijk
Copy link

fvanheeswijk commented Jul 13, 2020

Hello,

We are working on a complex product which uses web views internally to show webcontent, for this the WebBrowser component from WinForms is being used. But it has aged, has numerous issues and doesn't contain new innovations so logically we want to switch over to a newer product.
In the last years we have on and off done research and tried CefSharp3 at first and now the Essential Objects browser, they are all quite good but don't exactly cut it to go into production for all of us customers.

Now we are trying to see if this new promising WebView2 will be a nice fit but I'm seeing some worrying issues unfortunately. I don't know how much needs to be attributed to the fact that it still is a prerelease.

The major issue is that if something crashes the whole application crashes, whereas with CefSharp3 and Essential Objects only one specific browser window would crash but the application (together with other browser windows) would survive.

Soon I'll start digging into the more specific errors we are getting but for now these are the most common ones:

  • Exception : System.Runtime.InteropServices.COMException (0x8007139F): The group or resource is not in the correct state to perform the requested operation. (Exception from HRESULT: 0x8007139F)

    • Occurs when we remove event handlers from the CoreWebView2, this happens around the time we are destroying the form, we still need to make a reproducible example.
  • When we dispose the WebView2 when we close the form we get various unexpected errors. For now we have decided to not dispose, but is that correct usage?

  • System.Runtime.InteropServices.COMException (0x8007139F): The group or resource is not in the correct state to perform the requested operation. (Exception from HRESULT: 0x8007139F)

    • Occurs in Microsoft.Web.WebView2.Core.Raw.ICoreWebView2Controller.set_IsVisible(Int32 IsVisible) and originates from System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) or System.Windows.Forms.Control.WndProc(Message& m), it has to do something with escaping/closing a form with a webbrowser on it.

It may also be that we are partially the cause for our application crashes because we do not properly handle the exceptions, but how do we know whether an exception has originated from WebView2 and can thus be 'relatively safely' be discarded and when it would be an exception (which may also be a COMException) that has originated from other parts of our codebase and would result in an unstable program.

AB#27617140

@pagoe-msft pagoe-msft added bug Something isn't working .NET labels Jul 13, 2020
@pagoe-msft
Copy link

@fvanheeswijk ,

We completely understand your frustrations with WebBrowser component and CefSharp. This pre-release package is our first release of .NET binaries and is very much a work in progress until we GA. We plan to update our package every 6 weeks and would love for you to stay engaged and help us find bugs and suggest features as we work to develop a better product.

@fvanheeswijk
Copy link
Author

Okay, thank you for your response! The current state of this pre-release package got me a bit worried when attempting to integrate it into our existing product. I mean it probably works for most simple programs but our application is not quite that simple.

I'll file additional detailed bug reports with a reproducible example where possible for all bugs I encounter.

@fvanheeswijk
Copy link
Author

fvanheeswijk commented Jul 16, 2020

Any quick comments on this particular error message would be greatly appreciated:

System.Runtime.InteropServices.COMException (0x8007139F): The group or resource is not in the correct state to perform the requested operation. (Exception from HRESULT: 0x8007139F)
at Microsoft.Web.WebView2.Core.Raw.ICoreWebView2Controller.set_IsVisible(Int32 IsVisible)
at Microsoft.Web.WebView2.Core.CoreWebView2Controller.set_IsVisible(Boolean value)
at Microsoft.Web.WebView2.WinForms.WebView2.OnVisibleChanged(EventArgs e)
at System.Windows.Forms.Control.OnParentVisibleChanged(EventArgs e)
at System.Windows.Forms.Control.OnVisibleChanged(EventArgs e)
at System.Windows.Forms.Control.OnParentVisibleChanged(EventArgs e)
at System.Windows.Forms.Control.OnVisibleChanged(EventArgs e)
at System.Windows.Forms.Control.OnParentVisibleChanged(EventArgs e)
at System.Windows.Forms.Control.OnVisibleChanged(EventArgs e)
at System.Windows.Forms.Control.WmShowWindow(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

I've spent practically the entire day debugging this and still haven't managed to create a reproducible example, all I've got is the following:

  • It appears after closing a form (with the dispose also being visible in the call stack), in this case it was a modal form, not sure yet if relevant).
  • We use a custom subclass of a WinForms Panel on which we put controls including the WebView2, yet we get some NativeWindow calls on the call stack but have no reason why they are there so far. It appears that for some reason the webview wants to be shown while it also appears to have been disposed already.
  • The issue only reproduces in our actual application when forms are small enough to show scrollbars, it does not reproduce when no scrollbars are involved.

@champnic
Copy link
Member

@fvanheeswijk Thanks for trying out WebView2! We really appreciate the bug reports. Would you mind filing a separate GitHub issue for each bug you run into? It makes it easier to track and investigate on our end. As much info/code samples you can give will help us to reproduce and track down the issue as well.

For that stack, can you tell which controls are trying to set visibility on the WebView2? Is it setting visibility to true or false? It seems like this visibility call is trying to use the WebView2 after it has already been destroyed.

@champnic
Copy link
Member

Haven't heard back in a month, so closing this issue. If you have more details or want us to take another look please reopen. Thanks!

@carlossanlop
Copy link

@champnic this issue was most likely a duplicate of #228 . I am seeing a problem in the same callstack and I posted details about my repro. Can you please take a look at that issue?

@fvanheeswijk
Copy link
Author

This issue indeed does not reproduce anymore with the latest version of WebView2. However, we also changed parts of our own codebase, so I cannot determine if it's really fixed, but for us it is not an issue anymore.

@yu-zhou-tfs
Copy link

Hi

I also encountered the same issue with pre-release 1.0.647:

"System.Runtime.InteropServices.COMException (0x8007139F): The group or resource is not in the correct state to perform the requested operation. (Exception from HRESULT: 0x8007139F)\r\n
at Microsoft.Web.WebView2.Core.Raw.ICoreWebView2Controller.set_IsVisible(Int32 IsVisible)\r\n
at Microsoft.Web.WebView2.Core.CoreWebView2Controller.set_IsVisible(Boolean value)\r\n
at Microsoft.Web.WebView2.Wpf.WebView2.UIElement_IsVisibleChanged(Object sender, DependencyPropertyChangedEventArgs e)\r\n
at System.Windows.DependencyPropertyChangedEventHandler.Invoke(Object sender, DependencyPropertyChangedEventArgs e)\r\n
at System.Windows.UIElement.RaiseDependencyPropertyChanged(EventPrivateKey key, DependencyPropertyChangedEventArgs args)\r\n
at System.Windows.UIElement.OnIsVisibleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)\r\n
at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)\r\n
at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)\r\n
at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)\r\n
at System.Windows.UIElement.UpdateIsVisibleCache()\r\n
at System.Windows.UIElement.InvalidateForceInheritPropertyOnChildren(Visual v, DependencyProperty property)\r\n
at System.Windows.FrameworkElement.InvalidateForceInheritPropertyOnChildren(DependencyProperty property)\r\n
at System.Windows.UIElement.OnIsVisibleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)\r\n
at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)\r\n
at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)\r\n
at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)\r\n
at System.Windows.UIElement.UpdateIsVisibleCache()\r\n
at System.Windows.UIElement.InvalidateForceInheritPropertyOnChildren(Visual v, DependencyProperty property)\r\n
at System.Windows.FrameworkElement.InvalidateForceInheritPropertyOnChildren(DependencyProperty property)\r\n
at System.Windows.UIElement.OnIsVisibleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)\r\n
at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)\r\n
at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)\r\n
at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)\r\n
at System.Windows.UIElement.UpdateIsVisibleCache()\r\n
at System.Windows.UIElement.InvalidateForceInheritPropertyOnChildren(Visual v, DependencyProperty property)\r\n
at System.Windows.FrameworkElement.InvalidateForceInheritPropertyOnChildren(DependencyProperty property)\r\n
at System.Windows.UIElement.OnIsVisibleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)\r\n
at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)\r\n
at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)\r\n
at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)\r\n
at System.Windows.UIElement.UpdateIsVisibleCache()\r\n
at System.Windows.UIElement.InvalidateForceInheritPropertyOnChildren(Visual v, DependencyProperty property)\r\n
at System.Windows.FrameworkElement.InvalidateForceInheritPropertyOnChildren(DependencyProperty property)\r\n
at System.Windows.UIElement.OnIsVisibleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)\r\n
at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)\r\n
at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)\r\n
at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)\r\n
at System.Windows.UIElement.UpdateIsVisibleCache()\r\n
at System.Windows.UIElement.InvalidateForceInheritPropertyOnChildren(Visual v, DependencyProperty property)\r\n
at System.Windows.FrameworkElement.InvalidateForceInheritPropertyOnChildren(DependencyProperty property)\r\n
at System.Windows.UIElement.OnIsVisibleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)\r\n
at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)\r\n
at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)\r\n
at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)\r\n
at System.Windows.UIElement.UpdateIsVisibleCache()\r\n
at System.Windows.UIElement.InvalidateForceInheritPropertyOnChildren(Visual v, DependencyProperty property)\r\n
at System.Windows.FrameworkElement.InvalidateForceInheritPropertyOnChildren(DependencyProperty property)\r\n
at System.Windows.UIElement.OnIsVisibleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)\r\n
at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)\r\n
at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)\r\n
at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)\r\n
at System.Windows.UIElement.UpdateIsVisibleCache()\r\n
at System.Windows.UIElement.InvalidateForceInheritPropertyOnChildren(Visual v, DependencyProperty property)\r\n
at System.Windows.FrameworkElement.InvalidateForceInheritPropertyOnChildren(DependencyProperty property)\r\n
at System.Windows.UIElement.OnIsVisibleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)\r\n
at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)\r\n
at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)\r\n
at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)\r\n
at System.Windows.UIElement.UpdateIsVisibleCache()\r\n
at System.Windows.UIElement.InvalidateForceInheritPropertyOnChildren(Visual v, DependencyProperty property)\r\n
at System.Windows.FrameworkElement.InvalidateForceInheritPropertyOnChildren(DependencyProperty property)\r\n
at System.Windows.UIElement.OnIsVisibleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)\r\n
at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)\r\n
at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)\r\n
at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)\r\n
at System.Windows.UIElement.UpdateIsVisibleCache()\r\n
at System.Windows.PresentationSource.RootChanged(Visual oldRoot, Visual newRoot)\r\n
at System.Windows.Interop.HwndSource.set_RootVisualInternal(Visual value)\r\n
at System.Windows.Interop.HwndSource.Dispose(Boolean disposing)\r\n
at System.Windows.Interop.HwndSource.OnHwndDisposed(Object sender, EventArgs args)\r\n
at MS.Win32.HwndWrapper.Dispose(Boolean disposing, Boolean isHwndBeingDestroyed)\r\n
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)\r\n
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)\r\n
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)\r\n
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)\r\n
at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)\r\n
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)\r\n
at MS.Win32.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)\r\n
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)"

The webview2 WPF browser is used in a WPF UserControl wrapper (Com visible) and loaded in runtime by another main application as embedded view. The exception occurs when the main application is closed.

Environment:
.Net Framework 4.8
Windows 10 64 bit

@champnic
Copy link
Member

@yu-zhou-tfs WebView2 is single threaded - can you confirm that the visibility call is happening on the same thread that the WebView2 was created on?

You may need to call Dispose on the WebView2 when the main application is closing. That should clean up the CoreWebView2 object and remove the handler to IsVisibleChanged.

@GeminiBrian
Copy link

GeminiBrian commented Dec 2, 2020

I am experiencing the same issue. The WebView2 is in a WPF application on a form that is opened with ShowDialog. When the form closes, Dispose on the WebView2 is called in the Closing event of the form.

System.Runtime.InteropServices.COMException
HResult=0x8007139F
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)

Environment:

  • WebView2 1.0.664.37
  • WebView2 Runtime 87.0.664.52
  • .NET Framework 4.7.2
  • Windows 10 x64

@yu-zhou-tfs
Copy link

yu-zhou-tfs commented Dec 3, 2020

@yu-zhou-tfs WebView2 is single threaded - can you confirm that the visibility call is happening on the same thread that the WebView2 was created on?

You may need to call Dispose on the WebView2 when the main application is closing. That should clean up the CoreWebView2 object and remove the handler to IsVisibleChanged.

Hi the main application is a older Win Form application that we may not be able to change. I wrote a small Win Form app to load the same WebView2 WPF browser (in a separate assembly) during run time. Same exception happens when the Win Form application is closed.

It's caused by the base.Dispose() generated by designer.

     protected override void Dispose(bool disposing)
      {
          if (disposing && (components != null))
          {
              components.Dispose();
          }
          base.Dispose(disposing); // Exception raised here. Does the Dispose let GC finalizer thread to dispose WebView2 (as COM object) in this case?
      }

Within the Win Form I used ElementHost to host the WPF browser. The default Dispose method would not call ElementHost.Dispose but let base.Dispose(disposing) to deal with it.

If I added a call to explicitly to dispose the ElementHost, the exception would go away.

     protected override void Dispose(bool disposing)
      {
          if (disposing && (components != null))
          {
              components.Dispose();
          }
          DisposeControls();
          base.Dispose(disposing); 
      }

      private void DisposeControls()
      {
          if (m_wpfControlHost != null)
          {
              m_wpfControlHost.Dispose(); // This would dispose WebView2 in the same UI thread?
              this.Controls.Remove(m_wpfControlHost);
              m_wpfControlHost = null;
          }
      }

I don't know how to work around this as the legacy Win Form application cannot be changed. Please advise.

@priyasgs
Copy link

I see a similar issue, created one at #816

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

7 participants