【发布时间】:2021-02-24 07:43:13
【问题描述】:
我正在将浏览器集成到我的软件中。当我继续打开新的浏览器选项卡时它正在工作,但是一旦我关闭一个选项卡并尝试打开新的选项卡,它就会在以下代码中产生异常。
public async Task InitCore()
{
try
{
// Initialization.
await webView.EnsureCoreWebView2Async(null);
// This line gives exception if I close a tab and reopen as it gives exception in Initialization.
}
catch (Exception ex)
{
Enumerations.WriteToLog(Enumerations.LogType.Misc, "Browser.InitCore " + ex.ToString());
}
}
// Subscribing events.
private void AfterCoreReady(object sender,EventArgs e)
{
label1.Visible = false;
this.webView.CoreWebView2.ContentLoading += webView_ContentLoading;
this.webView.CoreWebView2.NewWindowRequested += webView_NewWindowRequested;
}
关闭选项卡后重新初始化时发生以下异常:
CustomWebView2.OnEnter System.Runtime.InteropServices.COMException (0x8007139F):
The group or resource is not in the correct state to perform the requested operation. (Exception from HRESULT: 0x8007139F)
at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode)
at Microsoft.Web.WebView2.Core.CoreWebView2Environment.<CreateCoreWebView2ControllerAsync>d__17.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Web.WebView2.WinForms.WebView2.<InitCoreWebView2Async>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at ProChart.Controls.Browser.<InitCore>d__16.MoveNext() in
Browser.cs:line 98
【问题讨论】:
-
是的,我也面临同样的问题。根据我的软件用户可以添加多个浏览器窗口选项卡。 WebView2 控件在我的 PC 中运行良好。但是当我试图关闭一个标签并在其他 PC 中打开另一个标签时,它给了我一个例外。