Microsoft Edge WebView2 - 加载时示例崩溃 [英] Microsoft Edge WebView2 - Sample crashes on Load
问题描述
我采用了最新版本的 Microsoft.Web.WebView2(0.9.515-预发行版)并添加到测试 C# WinForms 应用程序中.我使用的是 VS 2019,.NET 框架是 4.7.2.将 WebView2 控件放在表单上,编译并运行.应用程序在加载时崩溃,位于 Form1.designer.cs 中的以下位置.
I took the latest version of Microsoft.Web.WebView2 (0.9.515-prerelease) and added to a test C# WinForms application. Am using VS 2019, .NET framework is 4.7.2. Placed the WebView2 control on a form, compiled and ran. The application crashed on Load, at the below point in 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: 未将对象引用设置为对象的实例.
When I run this in Release mode, get the following exception trace - System.NullReferenceException: Object reference not set to an instance of an object.
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
If I take the latest stable version of WebView2 (v 0.9.488), it throws a compilation error as it does not reflect Microsoft.Web
请告诉我如何解决此错误.非常感谢您的帮助.8 个月前遇到了这个问题,但我希望微软现在已经超越了这个问题.如何使用C# windows 应用程序中的 Microsoft Edge WebView2 控件
Please let me know how to fix this error. Appreciate your help very much. Came across this question 8 months ago but am hoping Microsoft has gone beyond that now. How can I use the Microsoft Edge WebView2 control in C# windows application
微软创建的示例解决方案也有适用于 WinForms 的 C# 版本.https://github.com/MicrosoftEdge/WebView2Samples
The Sample solution Microsoft created does have C# version as well for WinForms. https://github.com/MicrosoftEdge/WebView2Samples
也尝试了 Microsoft 提供的此示例.它也会崩溃.https://docs.microsoft.com/en-us/microsoft-edge/webview2/gettingstarted/winforms
Tried this sample given by Microsoft as well. It too crashes. https://docs.microsoft.com/en-us/microsoft-edge/webview2/gettingstarted/winforms
推荐答案
您需要确保 1) Edge 版本正确.尝试从 URL https://c2rsetup.officeapps.live.com/c2r/downloadEdge.aspx?ProductreleaseID=Edge&platform=Default&version=Edge&source=EdgeInsiderPage&Channel=Canary&language=zh
you need to make sure 1) the Edge version is right. try download Canary version Edge from Url https://c2rsetup.officeapps.live.com/c2r/downloadEdge.aspx?ProductreleaseID=Edge&platform=Default&version=Edge&source=EdgeInsiderPage&Channel=Canary&language=en
和 2) 将 x86 设置为目标平台将解决问题.
and 2) set x86 as the target platform will fix the problem.
这篇关于Microsoft Edge WebView2 - 加载时示例崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!