我有一个简单的测试应用程序来测试在 C# 应用程序中嵌入 Microsoft 的 WebView2 控件,因为我想嵌入一个可以调用脚本等的浏览器。我安装了 NuGet 包,然后从 WebView2 的示例中获取代码:
public Form1()
{
InitializeComponent();
// Initialize WebView and add it to the Window's controls
WebView = new WebView2();
((ISupportInitialize)WebView).BeginInit();
WebView.Dock = DockStyle.Fill;
Controls.Add(WebView);
((ISupportInitialize)WebView).EndInit();
// Show the home page
WebView.Source = new Uri("https://www.microsoft.com");
}
但是,启动时会崩溃,并出现以下错误:
[0428/164447.586:ERROR:check.cc(382)] Check failed: false. NOTREACHED log messages are omitted in official builds. Sorry!
[0428/164448.301:ERROR:check.cc(382)] Check failed: false. NOTREACHED log messages are omitted in official builds. Sorry!
Exception thrown: 'System.Runtime.InteropServices.COMException' in Microsoft.Web.WebView2.Core.dll
Exception thrown: 'System.Runtime.InteropServices.COMException' in mscorlib.dll
Exception thrown: 'System.Runtime.InteropServices.COMException' in Microsoft.Web.WebView2.WinForms.dll
你知道我做错了什么吗?
谢谢
公共表格1(){ 初始化组件();
WebView2 webView=new WebView2();
webView.BeginInit();
webView.Dock=DockStyle.Fill;
Controls.Add(webView);
webView.EndInit();
webView.Source=new Uri("https://www.microsoft.com");
}