Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Webview 2 .NET (Windows Forms) NullReferenceException

Tags:

.net

Microsoft has finally released a pre-release of Webview2 for .NET. I followed the steps, but I keep getting a NullReferenceException on loading the form. How can I fix this?

System.InvalidOperationException: 'An error occurred creating the form. See Exception.InnerException
for details.  The error is: Object reference not set to an instance of an object.'

NullReferenceException: Object reference not set to an instance of an object.

This exception was originally thrown at this call stack:
Microsoft.Web.WebView2.WinForms.WebView2.OnVisibleChanged(System.EventArgs)
  System.Windows.Forms.Control.AssignParent(System.Windows.Forms.Control)
  System.Windows.Forms.Control.ControlCollection.Add(System.Windows.Forms.Control)
  System.Windows.Forms.Form.ControlCollection.Add(System.Windows.Forms.Control)
  Repair_VIP.Form_test.InitializeComponent() in Form_test.Designer.vb
like image 977
Mark Ismail Avatar asked May 21 '26 05:05

Mark Ismail


1 Answers

I also got nullreferenceexception on CoreWebView2. When calling webView. CoreWebView2.NavigateToString(); I added this before calling the Navigate method.

 await webView.EnsureCoreWebView2Async(null);

and everything worked fine.

like image 94
Asgar Avatar answered Jun 04 '26 23:06

Asgar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!