I am integrating Browser into my software. It is working when I keep on opening new browser tabs but as soon as I close one tab and try to open new one it produces an exception in following code.
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;
}
Following exception occurs while re-initialization after closing a tab:
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