WebView2 throw COMException (0x800401F0): CoInitialize has not been called. (0x800401F0 (CO_E_NOTINITIALIZED)) #3901
Replies: 3 comments
-
Hey @SkyIsWhite - Can you share a sample app that reproduces this issue? |
Beta Was this translation helpful? Give feedback.
-
webView = new Microsoft.Web.WebView2.Wpf.WebView2(); |
Beta Was this translation helpful? Give feedback.
-
Hey @SkyIsWhite - It's hard to know exactly what's wrong with the code you posted. The WebView2 needs to be created, run, and accessed on a Single Threaded Apartment (STA) COM thread - https://docs.microsoft.com/en-us/microsoft-edge/webview2/concepts/threading-model Typically this is done for you by WPF or Winforms. From the looks of your code and not using .xaml, I'm assuming you are creating the WebView2 off of the WPF UI thread. Is there a reason you are avoiding using XAML? Can you try creating the WebView2 on the UI thread? |
Beta Was this translation helpful? Give feedback.
-
Description
1 Call CoreWebView2Environment.CreateAsync throw exception
2 this call was in main thread
3 has no another one
Stack
,CoreWebView2InitializationCompleted,InitializationException=System.Runtime.InteropServices.COMException (0x800401F0): CoInitialize has not been called. (0x800401F0 (CO_E_NOTINITIALIZED))
at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode)
at Microsoft.Web.WebView2.Core.CoreWebView2Environment.CreateAsync(String browserExecutableFolder, String userDataFolder, CoreWebView2EnvironmentOptions options)
at Microsoft.Web.WebView2.Wpf.WebView2.<>cDisplayClass26_0.<gInit|0>d.MoveNext(),Return
Version
SDK: 1.0.902.49
Runtime: edg/92.0.902.67
Framework: wpf
code
webView = new Microsoft.Web.WebView2.Wpf.WebView2();
webView.BeginInit();
webView.CoreWebView2InitializationCompleted += WebView_CoreWebView2InitializationCompleted;
webView.CreationProperties = new CoreWebView2CreationProperties();
webView.CreationProperties.UserDataFolder = UserDataPath;
this.grid.Children.add(webView);
webView.EndInit();
await webView.EnsureCoreWebView2Async();
Beta Was this translation helpful? Give feedback.
All reactions