Microsoft Edge WebView2-示例在加载时崩溃

问题描述 投票:2回答:1

我采用了最新版本的Microsoft.Web.WebView2(0.9.515-prerelease),并将其添加到测试的C#WinForms应用程序中。我正在使用VS 2019,.NET框架为4.7.2。将WebView2控件放置在窗体上,进行编译并运行。应用程序在加载时崩溃,位于Form1.designer.cs的以下位置。

    // webView21
    // 
    this.webView21.Location = new System.Drawing.Point(153, 66);
    this.webView21.Name = "webView21";
    this.webView21.Size = new System.Drawing.Size(492, 253);
    this.webView21.Source = new System.Uri("about:blank", System.UriKind.Absolute);
    this.webView21.TabIndex = 0;
    this.webView21.Text = "webView21";
    this.webView21.ZoomFactor = 1D;
    // 
    // Form1
    // 
    this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    this.ClientSize = new System.Drawing.Size(800, 450);
    this.Controls.Add(this.webView21); //CRASHED HERE WITH BELOW EXCEPTION -

当我在发布模式下运行此命令时,获得以下异常跟踪-System.NullReferenceException:对象引用未设置为对象的实例。

   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.ScrollableControl.OnVisibleChanged(EventArgs e)
   at System.Windows.Forms.Form.OnVisibleChanged(EventArgs e)
   at System.Windows.Forms.Control.WmShowWindow(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   at System.Windows.Forms.Form.WmShowWindow(Message& m)
   at System.Windows.Forms.Form.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

如果我使用最新的稳定版本的WebView2(v 0.9.488),则会抛出编译错误,因为它不反映Microsoft.Web。>

[请让我知道如何解决此错误。非常感谢您的帮助。 8个月前遇到了这个问题,但我希望微软现在已经超越了这个问题。How can I use the Microsoft Edge WebView2 control in C# windows application

Microsoft创建的示例解决方案的WinForms也具有C#版本。https://github.com/MicrosoftEdge/WebView2Samples

[也尝试了Microsoft提供的此示例。它也崩溃了。https://docs.microsoft.com/en-us/microsoft-edge/webview2/gettingstarted/winforms

我采用了最新版本的Microsoft.Web.WebView2(0.9.515-prerelease),并将其添加到测试的C#WinForms应用程序中。我正在使用VS 2019,.NET框架为4.7.2。将WebView2控件放在窗体上,...

visual-studio-2019 webview2
1个回答
0
投票

从我的Edge的路径“ C:\ Program Files(x86)\ Microsoft \ Edge \ Application \ msedge.exe”开始,我们可以得出结论,当前Edge是32位程序?尝试将平台目标设置为x86。一些专家说,设置了x86,就可以了!

© www.soinside.com 2019 - 2024. All rights reserved.