Windows 11 laptops eventually unable to initialize the WebView2 runtime, get COMException
Description Users on Windows 11 laptops (so far it's only laptops, we haven't seen this on VMs or workstations) will start off running our WPF WebView2 app fine, but will eventually be unable to initialize the runtime. CoreWebView2InitializationCompletedEventArgs.InitializationException is
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 Microsoft.Web.WebView2.Core.CoreWebView2Environment.<CreateCoreWebView2ControllerAsync>d__49.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task) at Microsoft.Web.WebView2.Wpf.WebView2.<>c__DisplayClass27_0.<<EnsureCoreWebView2Async>g__Init|0>d.MoveNext()
I can fix them by providing a new runtime, but eventually the problem re-emerges. I had one user Repair the evergreen WebView2 on their laptop and initialization worked ok for a little while then the error came back.
We deploy a fixed runtime (currently 98.0.1108.56), and if initialization of that fails, we attempt the Evergreen runtime. Eventually, both runtimes will fail to initialize.
Deleting the deployed runtime and re-expanding the cab file does not fix the problem.
Restarts do not fix the problem.
Windows 10 users have not reported this problem.
Since we want to use a runtime we deploy, we do initialization in an IntializeAsync method that is called in MainWindow_Loaded: var env = await CoreWebView2Environment.CreateAsync(browserExecutableFolder, dataFolder); await webView.EnsureCoreWebView2Async(env);
Are we doing something wrong with initialization?
Version SDK: 1.0.1108.44 Runtime: 98.0.1108.56 Framework: WPF OS: Win 11
Repro Steps
Screenshots
Additional context
Hey @Mike-Johns - thanks for the bug report!
Are you seeing this with every laptop Win11 users, or just some? Are those machines resource constrained?
The strangest part of this bug to me is that a machine restart doesn't fix the issue, which would suggest it's not a resource issue, nor an issue of using old runtime or other apps using the same processes. Does your app only initialize one WebView2, or multiple at the same time?
Or perhaps it's something that corrupts the runtime itself on those machines. Is there an antivirus running that could be interfering with those runtimes?
Hi @champnic - thanks for the reply!
It just started happening to one of our users again. He was running fine since Saturday and suddenly can't initialize the runtime with the error
WebView2 creation failed with exception = 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 Microsoft.Web.WebView2.Core.CoreWebView2Environment.<CreateCoreWebView2ControllerAsync>d__58.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task) at Microsoft.Web.WebView2.Wpf.WebView2.<>c__DisplayClass27_0.<<EnsureCoreWebView2Async>g__Init|0>d.MoveNext()
Reboot doesn't help, which I agree is really weird.
He's running malwarebytes, but he disabled and even uninstalled that and still has the error.
We do have two apps using the runtime, but they're two separate apps and run independently. I assume the runtime can support multiple apps using it.
If I download a new runtime cab and deploy that to his laptop, it will work again.
If I delete the runtime he's currently trying to use and expand the cab file again, it will not work. It will get the same error, which I also think is really weird.
Let me share my code around initialization, in case something stands out to you.
Thanks for your help!
public MainWindow()
{
InitializeComponent();
webView.CoreWebView2InitializationCompleted += WebView_CoreWebView2InitializationCompleted;
this.Loaded += MainWindow_Loaded;
}
private async void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
//get the path to the runtime we deployed
string browserExecutableFolder = GetBrowserExecutableFolder();
await InitializeAsync(browserExecutableFolder);
}
private async Task InitializeAsync(string browserExecutableFolder)
{
try
{
string dataFolder = Path.Combine(Path.GetTempPath(), appName);
if (!System.IO.Directory.Exists(dataFolder))
{
System.IO.Directory.CreateDirectory(dataFolder);
}
var env = await CoreWebView2Environment.CreateAsync(browserExecutableFolder, dataFolder);
if (webView != null)
{
await webView.EnsureCoreWebView2Async(env);
webView.NavigationCompleted += WebView_NavigationCompleted;
webView.WebMessageReceived += WebView_WebMessageReceived;
webView.NavigationStarting += WebView_NavigationStarting;
}
else
{
//log an error message that webView is null
}
}
catch (Exception e)
{
//log the exception
}
}
private async void WebView_CoreWebView2InitializationCompleted(object sender, CoreWebView2InitializationCompletedEventArgs e)
{
try
{
if (!e.IsSuccess)
{
//log the error
//try disposing that webview and load the OS-provided one
try
{
if (numReTries < 1)
{
numReTries++;
try
{
string installedWebView2Version = CoreWebView2Environment.GetAvailableBrowserVersionString();
}
catch (WebView2RuntimeNotFoundException)
{
//log the error
return;
}
//I got this idea from your sample project.
Layout.Children.Remove(webView);
webView.Dispose();
webView = GetReplacementControl(null);
Layout.Children.Add(webView);
await InitializeAsync(null);
}
else
{
//show an error
}
}
catch (Exception exc)
{
//log the error
}
}
else
{
//successful initialization.
// this loads an HTML file we deployed to the filesystem.
LoadLocalWebPage();
DomManipulationDotnetInterop DotnetInterop = new DomManipulationDotnetInterop();
webView.CoreWebView2.AddHostObjectToScript("dotnet", DotnetInterop);
webView.CoreWebView2.PermissionRequested += CoreWebView2_PermissionRequested;
webView.CoreWebView2.ProcessFailed += CoreWebView2_ProcessFailed;
}
}
catch (Exception exc)
{
//log the exception
}
}
I did some more experimenting on the user's machine and discovered that if I expand the cab file into a new directory (this time in a subdirectory of his TEMP folder), initialization succeeds. But if we delete the previous runtime location (in our Program Files subdir) and re-expand the cab file, it will fail.
If I download a new runtime cab and deploy that to his laptop, it will work again.
Yes - multiple apps can use the same runtime. If they are also using the same user data folder, then they need to match command line args when initializing the WebView2 (because they will be sharing the same browser process).
Do you have confirmation of a runtime in Program Files working? I'm wondering if it could be an access issue?
It works until it doesn't and we get the COM error (0x8007139f). It just happened to the user again, this time with the runtime in his %TEMP% folder. Deleting the runtime and re-expanding the cab file doesn't help. If I grab a new runtime cab file (resulting in a different folder after expansion) or expand the current one to a different directory, it will work.
He ran sfc /scannow and while it didn't report any problems, he is able to use the evergreen runtime after running that. But the runtime we deployed is still unable to initialize.
The two apps are using different user data folders. Each app gets its own user data folder. Deleting the data folder doesn't make a difference.
Is Windows somehow flagging the runtime as "bad"? I don't understand how expanding the same runtime to a different directory gets it working again (for a little while), but deleting the runtime folder and re-expanding to the same path stays broken.
His antivirus software is Windows Defender. His protection history is blank.
That could maybe be what's happening, although I would be surprised. I've added this bug to our backlog so we can take a closer look.
@Mike-Johns, you could take a look whether there is kind of compatibility mode set to the msedgewebview2.exe. That mode is sticky to the name of the path, stored in registry HKCU\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers.
Hi! I see an entry for each msedgewebview2.exe at that location. All of them have the data HIGHDPIAWARE.
From: SvenPStarFinanz @.***> Sent: Tuesday, March 8, 2022 11:31:14 AM To: MicrosoftEdge/WebView2Feedback Cc: Michael Johnson; Mention Subject: Re: [MicrosoftEdge/WebView2Feedback] Windows 11 laptops eventually unable to initialize the WebView2 runtime, get COMException (Issue #2226)
@Mike-Johnshttps://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FMike-Johns&data=04%7C01%7CMichael_Johnson%40virnetx.com%7C529a29c9fca8499ae55708da0131d435%7C9672efb1715b42afbe8c7d6ccd1794a3%7C1%7C0%7C637823610778681305%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=El%2FGkTB9awm07WzGGz%2Flmlg9NSvM8UralBULpjrmGVE%3D&reserved=0, you could take a look whether there is kind of compatibility mode set to the msedgewebview2.exe. That mode is sticky to the name of the path, stored in registry HKCU\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers.
— Reply to this email directly, view it on GitHubhttps://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FMicrosoftEdge%2FWebView2Feedback%2Fissues%2F2226%23issuecomment-1062080231&data=04%7C01%7CMichael_Johnson%40virnetx.com%7C529a29c9fca8499ae55708da0131d435%7C9672efb1715b42afbe8c7d6ccd1794a3%7C1%7C0%7C637823610778681305%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=OU%2BT8AuAgX0N2A%2B3GLPgnBx%2FvOAGzIX9ImpiKdyDZQs%3D&reserved=0, or unsubscribehttps://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAX6VPPOPPYL64J464RYWEM3U66MHFANCNFSM5PNQPQLA&data=04%7C01%7CMichael_Johnson%40virnetx.com%7C529a29c9fca8499ae55708da0131d435%7C9672efb1715b42afbe8c7d6ccd1794a3%7C1%7C0%7C637823610778681305%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=771Xb%2BUIDzLl%2B7iD6%2FciCb%2FDtrRYmo2P41vglzJQj0c%3D&reserved=0. Triage notifications on the go with GitHub Mobile for iOShttps://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fapps.apple.com%2Fapp%2Fapple-store%2Fid1477376905%3Fct%3Dnotification-email%26mt%3D8%26pt%3D524675&data=04%7C01%7CMichael_Johnson%40virnetx.com%7C529a29c9fca8499ae55708da0131d435%7C9672efb1715b42afbe8c7d6ccd1794a3%7C1%7C0%7C637823610778681305%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=PJtGX0Orj2Qh1aj%2FSFd8XJM%2FXNaAxBIdfetRSvRD9Eg%3D&reserved=0 or Androidhttps://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fplay.google.com%2Fstore%2Fapps%2Fdetails%3Fid%3Dcom.github.android%26referrer%3Dutm_campaign%253Dnotification-email%2526utm_medium%253Demail%2526utm_source%253Dgithub&data=04%7C01%7CMichael_Johnson%40virnetx.com%7C529a29c9fca8499ae55708da0131d435%7C9672efb1715b42afbe8c7d6ccd1794a3%7C1%7C0%7C637823610778837543%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=JSut%2BgwPrpQ1ZzIs8IoCH7gxzeqNUmm1oOoq3QlovB8%3D&reserved=0. You are receiving this because you were mentioned.Message ID: @.***>
We had similar issues errors. Our problem was that the datafolder was reused with different language settings for WebView2 between instances of our application.
Now we generate a hash based on all command lite arguments and settings to ensure compatible datafolders.
Hi! I see an entry for each msedgewebview2.exe at that location. All of them have the data HIGHDPIAWARE. … ________________________________ From: SvenPStarFinanz @.> Sent: Tuesday, March 8, 2022 11:31:14 AM To: MicrosoftEdge/WebView2Feedback Cc: Michael Johnson; Mention Subject: Re: [MicrosoftEdge/WebView2Feedback] Windows 11 laptops eventually unable to initialize the WebView2 runtime, get COMException (Issue #2226) @Mike-Johnshttps://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FMike-Johns&data=04%7C01%7CMichael_Johnson%40virnetx.com%7C529a29c9fca8499ae55708da0131d435%7C9672efb1715b42afbe8c7d6ccd1794a3%7C1%7C0%7C637823610778681305%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=El%2FGkTB9awm07WzGGz%2Flmlg9NSvM8UralBULpjrmGVE%3D&reserved=0, you could take a look whether there is kind of compatibility mode set to the msedgewebview2.exe. That mode is sticky to the name of the path, stored in registry HKCU\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers. — Reply to this email directly, view it on GitHubhttps://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FMicrosoftEdge%2FWebView2Feedback%2Fissues%2F2226%23issuecomment-1062080231&data=04%7C01%7CMichael_Johnson%40virnetx.com%7C529a29c9fca8499ae55708da0131d435%7C9672efb1715b42afbe8c7d6ccd1794a3%7C1%7C0%7C637823610778681305%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=OU%2BT8AuAgX0N2A%2B3GLPgnBx%2FvOAGzIX9ImpiKdyDZQs%3D&reserved=0, or unsubscribehttps://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAX6VPPOPPYL64J464RYWEM3U66MHFANCNFSM5PNQPQLA&data=04%7C01%7CMichael_Johnson%40virnetx.com%7C529a29c9fca8499ae55708da0131d435%7C9672efb1715b42afbe8c7d6ccd1794a3%7C1%7C0%7C637823610778681305%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=771Xb%2BUIDzLl%2B7iD6%2FciCb%2FDtrRYmo2P41vglzJQj0c%3D&reserved=0. Triage notifications on the go with GitHub Mobile for iOShttps://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fapps.apple.com%2Fapp%2Fapple-store%2Fid1477376905%3Fct%3Dnotification-email%26mt%3D8%26pt%3D524675&data=04%7C01%7CMichael_Johnson%40virnetx.com%7C529a29c9fca8499ae55708da0131d435%7C9672efb1715b42afbe8c7d6ccd1794a3%7C1%7C0%7C637823610778681305%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=PJtGX0Orj2Qh1aj%2FSFd8XJM%2FXNaAxBIdfetRSvRD9Eg%3D&reserved=0 or Androidhttps://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fplay.google.com%2Fstore%2Fapps%2Fdetails%3Fid%3Dcom.github.android%26referrer%3Dutm_campaign%253Dnotification-email%2526utm_medium%253Demail%2526utm_source%253Dgithub&data=04%7C01%7CMichael_Johnson%40virnetx.com%7C529a29c9fca8499ae55708da0131d435%7C9672efb1715b42afbe8c7d6ccd1794a3%7C1%7C0%7C637823610778837543%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=JSut%2BgwPrpQ1ZzIs8IoCH7gxzeqNUmm1oOoq3QlovB8%3D&reserved=0. You are receiving this because you were mentioned.Message ID: @.>
https://github.com/MicrosoftEdge/WebView2Feedback/issues/3008#issuecomment-1916313157
Removing that key fixed the issue for me. See above comment