首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >微软边缘WebView2 -示例加载时崩溃

微软边缘WebView2 -示例加载时崩溃
EN

Stack Overflow用户
提问于 2020-05-19 15:50:31
回答 8查看 6.8K关注 0票数 9

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

代码语言:javascript
复制
    // 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: object reference未设置为对象的实例。

代码语言:javascript
复制
   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的最新稳定版本(v0.9.488),它会抛出一个编译错误,因为它没有反映Microsoft.Web

请告诉我如何修复这个错误。非常感谢你的帮助。我在8个月前遇到过这个问题,但我希望微软现在已经超越了这个问题。How can I use the Microsoft Edge WebView2 control in C# windows application

微软创建的示例解决方案也有适用于WinForms的C#版本。https://github.com/MicrosoftEdge/WebView2Samples

也尝试了微软提供的这个示例。它也会崩溃。https://docs.microsoft.com/en-us/microsoft-edge/webview2/gettingstarted/winforms

EN

回答 8

Stack Overflow用户

发布于 2020-05-20 12:18:33

您需要确保1) Edge版本是正确的。尝试从Url https://c2rsetup.officeapps.live.com/c2r/downloadEdge.aspx?ProductreleaseID=Edge&platform=Default&version=Edge&source=EdgeInsiderPage&Channel=Canary&language=en下载金丝雀版边缘

2)将x86设置为目标平台可以解决这个问题。

票数 5
EN

Stack Overflow用户

发布于 2020-07-11 09:06:05

我面临着同样的问题,但我能够解决它。每当traget CPU为"Any CPU“时,它就会崩溃,但如果您将其更改为"x86”或"x64",在我的例子中,它将成功运行。它似乎不能检查和使用未指定的目标CPU架构。

我希望这能帮你省去很多麻烦

票数 2
EN

Stack Overflow用户

发布于 2020-09-07 03:39:16

不幸的是,这在0.9.515-预发行版中仍然是一个问题。这是一个打开的bug,我添加了更多关于我的复制品的细节:

https://github.com/MicrosoftEdge/WebViewFeedback/issues/228#issuecomment-687873636

编辑:如果您安装x64 bits边缘,则x86建议不适用于您。你可以为x64构建它,它将会工作。有关更多详细信息,请参阅我在该问题上的回应:https://github.com/MicrosoftEdge/WebViewFeedback/issues/228#issuecomment-687900181

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61885845

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档