MicrosoftEdge / WebView2Samples

Microsoft Edge WebView2 samples
871 stars 471 forks source link

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

Open anilgenius opened 4 years ago

anilgenius commented 4 years ago

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

MinChanSike commented 4 years ago

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

champnic commented 4 years ago

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?

MinChanSike commented 4 years ago

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.

LukeOwlclaw commented 4 years ago

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

champnic commented 4 years ago

@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!

LukeOwlclaw commented 4 years ago

@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

champnic commented 4 years ago

@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.

LukeOwlclaw commented 4 years ago

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?

champnic commented 4 years ago

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

LukeOwlclaw commented 4 years ago

@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...

erpcto commented 4 years ago

I have the same problem version 0.9.628 Dev channel

erpcto commented 4 years ago

QQ图片20201014162434

champnic commented 4 years ago

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

erpcto commented 4 years ago

@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.

champnic commented 4 years ago

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

erpcto commented 4 years ago

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