WebView2Samples icon indicating copy to clipboard operation
WebView2Samples copied to clipboard

WinForm Sample - unable to run due to error ('Object reference not set to an instance of an object.')

Open anilgenius opened this issue 5 years ago • 16 comments

in the winform sample system.nullreferenceexception came on
line this.Controls.Add(this.webView2Control);

anilgenius avatar Jun 21 '20 17:06 anilgenius

same error, System.NullReferenceException: 'Object reference not set to an instance of an object.' Building on Visual Studio 2019

StackTrace at Microsoft.Web.WebView2.WinForms.WebView2.OnVisibleChanged(EventArgs e) at System.Windows.Forms.Control.AssignParent(Control value) at System.Windows.Forms.Control.ControlCollection.Add(Control value) at System.Windows.Forms.Form.ControlCollection.Add(Control value) at WebView2WindowsFormsBrowser.BrowserForm.InitializeComponent() in ...\WebView2Samples\WebView2WindowsFormsBrowser\BrowserForm.Designer.cs:line 215

MinChanSike avatar Jun 24 '20 12:06 MinChanSike

Thanks for trying out the sample apps! Can you expand a bit on what you were trying to do when you experienced this error? Is there a specific action within the app that led to this, or was it on launch?

champnic avatar Jun 24 '20 17:06 champnic

Application could not launch, it throw System.NullReferenceException on Form InitializeComponent . After installation Microsoft Edge BETA Version 84.0.522.26 on computer, fixed and working now. Thanks.

MinChanSike avatar Jun 25 '20 01:06 MinChanSike

Using "Version 84.0.522.40 (Official build)" the problem is still present.

LukeOwlclaw avatar Jul 21 '20 04:07 LukeOwlclaw

@LukeOwlclaw Can you tell me what channel that Edge build is? What version of the SDK are you using? Could you add some repro steps that led to that error for you?

@MinChanSike Glad the issue resolved for you!

champnic avatar Jul 21 '20 05:07 champnic

@champnic I just installed Edge and did not change the channel. Then I created a WinForms C# project (.NET Framework 4.7.2), installed WebView2 NuGet version 0.9.515-prerelease (because that is the latest version which supports my Edge version), dropped a WebView2 component on the form, and hit run ==> image

LukeOwlclaw avatar Jul 21 '20 05:07 LukeOwlclaw

@LukeOwlclaw Are you using the stable channel of Edge? If so you need to use a Canary or Dev build of Edge. Or you can use the WebView2 Runtime.

I just tried your steps locally (Using 0.9.515-prerelease, VS 2019 16.6.2, WV2RT 85.0.564.8) and created a WinForms app, dropped the control, and it worked fine.

champnic avatar Jul 21 '20 15:07 champnic

Yes, I am using the stable channel. It is currently at 84.0.522. The release notes for the WebView2 version I am using (0.9.515-prerelease), states:

minimum Microsoft Edge version 84.0.515.0.

So it should work, shouldn't it?

LukeOwlclaw avatar Jul 23 '20 05:07 LukeOwlclaw

Unfortunately we don't support the stable channel, only the Canary/Dev/Beta and the Runtime. @liminzhu has more details here: https://github.com/MicrosoftEdge/WebViewFeedback/issues/341#issuecomment-662719106

champnic avatar Jul 23 '20 23:07 champnic

@champnic Thanks for the link. Though I do not understand why the distribution channel matters if the release version is exactly the same. But I guess it'll come all together once it is released...

LukeOwlclaw avatar Jul 27 '20 11:07 LukeOwlclaw

I have the same problem version 0.9.628 Dev channel

erpcto avatar Oct 14 '20 08:10 erpcto

QQ图片20201014162434

erpcto avatar Oct 14 '20 08:10 erpcto

@erpcto Is your issue with the sample app or your own app?

champnic avatar Oct 14 '20 17:10 champnic

@erpcto Is your issue with the sample app or your own app?

This exception is prompted when my new program references the control and runs.

erpcto avatar Oct 15 '20 01:10 erpcto

What version of Edge/Runtime are you using? It's possible you're hitting https://github.com/MicrosoftEdge/WebView2Feedback/issues/535.

champnic avatar Oct 15 '20 02:10 champnic

I use the Dev channel

What version of Edge/Runtime are you using? It's possible you're hitting MicrosoftEdge/WebView2Feedback#535. I use the Dev channel

erpcto avatar Oct 15 '20 02:10 erpcto