Skip to content

[Problem/Bug]: System.Runtime.InteropServices.COMException #5279

Open
@SamXi2023

Description

@SamXi2023

What happened?

hello everyone, I got this trouble, can you help me?

Microsoft.Web.WebView2.Core 1.0.3296.44

2025-06-18 11:22:38,538 [1] INFO WebviewWrapper - retryCount: 1
2025-06-18 11:22:38,749 [1] ERROR WebviewWrapper - Exception Type: System.Runtime.InteropServices.COMException
2025-06-18 11:22:38,750 [1] ERROR WebviewWrapper - Message: 已中止操作 (异常来自 HRESULT:0x80004004 (E_ABORT))
2025-06-18 11:22:38,806 [1] ERROR WebviewWrapper - StackTrace: 在 System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
在 Microsoft.Web.WebView2.Core.CoreWebView2Environment.d__15.MoveNext()
--- 引发异常的上一位置中堆栈跟踪的末尾 ---
在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
在 System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
在 Microsoft.Web.WebView2.WinForms.WebView2.d__25.MoveNext()
--- 引发异常的上一位置中堆栈跟踪的末尾 ---
在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
在 System.Runtime.CompilerServices.TaskAwaiter.GetResult()
在 WebviewWrapper.WebviewForm.d__8.MoveNext()
2025-06-18 11:22:39,004 [1] INFO WebviewWrapper - retryCount: 2
2025-06-18 11:22:39,006 [1] ERROR WebviewWrapper - Exception Type: System.InvalidOperationException
2025-06-18 11:22:39,006 [1] ERROR WebviewWrapper - Message: The instance of CoreWebView2 is disposed and unable to complete this operation.
2025-06-18 11:22:39,007 [1] ERROR WebviewWrapper - StackTrace: 在 Microsoft.Web.WebView2.WinForms.WebView2.VerifyNotClosedGuard()
在 Microsoft.Web.WebView2.WinForms.WebView2.EnsureCoreWebView2Async(CoreWebView2Environment environment, CoreWebView2ControllerOptions controllerOptions)
在 Microsoft.Web.WebView2.WinForms.WebView2.EnsureCoreWebView2Async(CoreWebView2Environment environment)

Importance

Blocking. My app's basic functions are not working due to this issue.

Runtime Channel

Stable release (WebView2 Runtime)

Runtime Version

No response

SDK Version

No response

Framework

Winforms

Operating System

Windows 11

OS Version

No response

Repro steps

public static async Task GetEnvironmentAsync(string userDataFolderTag, bool bDebug, int logLevel)
{
if (_sharedEnvironment != null)
return _sharedEnvironment;

string exeDir = AppDomain.CurrentDomain.BaseDirectory;
string userDataFolder = Path.Combine(exeDir, userDataFolderTag);

var args = new List<string>
{
    "--disable-web-security",
    "--allow-file-access-from-files",
    "--disable-application-cache --disable-cache",
    "--disk-cache-size=0"
};

if (bDebug)
{
    args.Add("--enable-logging");
    args.Add("--v=" + logLevel);
    args.Add("--remote-debugging-port=" + GetAvailablePort());
}

var options = new CoreWebView2EnvironmentOptions
{
    AdditionalBrowserArguments = string.Join(" ", args)
};

_sharedEnvironment = await CoreWebView2Environment.CreateAsync(null, userDataFolder, options);

return _sharedEnvironment;

}

var sharedEnv = await WebView2EnvironmentManager.GetEnvironmentAsync("WebView2Data", bDebug, logLevel);

await webView.EnsureCoreWebView2Async(sharedEnv);

Repros in Edge Browser

No, issue does not reproduce in the corresponding Edge version

Regression

Don't know

Last working version (if regression)

No response

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions