-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Problem/Bug]: Cannot change thread mode after it is set. #4361
Labels
Comments
@joshholmes @quietfanatic @oggy22 @yildirimcagri-msft |
WebView2 by design requires running from STA: https://learn.microsoft.com/en-us/microsoft-edge/webview2/concepts/threading-model. Try to see whether there is any code calling CoInitializeEx with COINIT_MULTITHREADED. Try change that to be COINIT_APARTMENTTHREADED. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What happened?
When I am using multiple Window application and I want to open a new form of XYZ application, from ABC application, I am using main and ui thread approach, but when i am trying to access XYZ application form that basically uses WebView2 controls, I get an error when i call below code
try
{
var environment = await CoreWebView2Environment.CreateAsync(null, null);
}
Error detail
************** Exception Text **************
System.Runtime.InteropServices.COMException (0x80010106): Cannot change thread mode after it is set. (0x80010106 (RPC_E_CHANGED_MODE))
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.WinForms.WebView2.InitCoreWebView2Async(CoreWebView2Environment environment, CoreWebView2ControllerOptions controllerOptions)
at UTIL.App.AlertItemForm.InitializeAsync() in C:\FDB\DEV\UTIL\src\App\ItemForm.cs:line 383
at System.Threading.Tasks.Task.<>c.b__128_0(Object state)
at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
at System.Reflection.MethodInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr)
Importance
Blocking. My app's basic functions are not working due to this issue.
Runtime Channel
Stable release (WebView2 Runtime)
Runtime Version
1.0.2277.86
SDK Version
1.0.2277.86
Framework
Winforms
Operating System
Windows 11
OS Version
No response
Repro steps
Run the code and getting above issue
Repros in Edge Browser
No
Regression
No, this never worked
Last working version (if regression)
1.0.2277.86
The text was updated successfully, but these errors were encountered: