WebView2 WinForms c# "3. Getting Started" Errors ?

vmars316 621 Reputation points
2020-10-14T00:02:28.213+00:00

Hello;

I am at 'Step 3 - Create a single WebView'

https://learn.microsoft.com/en-us/microsoft-edge/webview2/gettingstarted/winforms

But when I compile program I get the following error;

System.NullReferenceException  
HResult=0x80004003  
Message=Object reference not set to an instance of an object.  
Source=Microsoft.Web.WebView2.WinForms  
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 WinFormsGettngStarted.Form1.InitializeComponent() in C:\Users\vmars\source\repos\WinFormsGettngStarted\Form1.Designer.cs:line 50  
  
  
From this line:  this.Controls.Add(this.webView);   
  

How can I get past this error ?

Thanks for yur Help...

Developer technologies Windows Forms
0 comments No comments
{count} votes

Accepted answer
  1. Tianyu Sun-MSFT 34,436 Reputation points Microsoft External Staff
    2020-10-14T06:48:31.057+00:00

    Hello Vernon,

    Thank you for taking time to post this issue in Microsoft Q&A forum.

    This issue is caused by not choosing appropriate Platform target, please go to the properties page of your Winform project (right-click > Properties), then click Build > Platform target and choose x64 then press F5 to test again.

    32190-1.png

    Sincerely,
    Tianyu

    • If the answer is helpful, please click "Accept Answer" and upvote it.
      Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. vmars316 621 Reputation points
    2020-10-14T14:38:16.067+00:00

    Thank you TianyuSun !

    0 comments No comments

  2. Ilija Dimitrov 1 Reputation point
    2021-01-07T05:14:52.353+00:00

    On My app this doesn't work.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.