RPC_E_CHANGED_MODE (0x80010106) Error
I'm experimenting with Wails and used some simple Go code that queries some hardware settings. When doing so, I get an RPC_E_CHANGED_MODE error. I think this is related to how the WebView2 COM instance is created.
Any idea how and where to best fix this?
- In WebView2
- in Wails and how it's using WebView2
- In the hardware querying package
This usually happens when you try to CoInitialize a second time, but try to create an STA when there is already a MTA.
I guess it would be necessary for us to have some way to allow you to initialize an STA. Honestly, I haven’t thought through entirely what the implications are of using multi-threaded apartments with Go code. You could modify the CoInitialize call in the other library to match the CoInitialize call in this one and then this issue should disappear, though I am not sure if that will cause any subtle problems or not. Need to think more.
I resolved the issue by changing the library code to not return an error when the return code is RPC_E_CHANGED_MODE but continue because one ignore this case and just continue. The 1st initialization variant is used/wins.
I think the best solution for any library code is, to try the initialization (necessary for cases where you are the first) and ignore the RPC_E_CHANGED_MODE error code. Double initialization doesn't harm, and initialization with a different mode can be ignored.