Skip to content
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]: Microsoft.Web.WebView2 throws an System.Runtime.InteropServices.COMException (0x8007139F) randomly #4218

Open
NearEternal opened this issue Dec 6, 2023 · 15 comments
Assignees
Labels
bug Something isn't working

Comments

@NearEternal
Copy link

What happened?

This is crazy! I got a System.Runtime.InteropServices.COMException: 'The group or resource is not in the state required to perform the requested operation. (0x8007139F)' at very simple sample Application. I simplify made basic Microsoft Visual Studio 2022 Windows c# Forms Application and add latest stable version of that Microsoft.Web.WebView2 nuget package, some Designer changes and that code below:

using Microsoft.Web.WebView2.Core;
using Microsoft.Web.WebView2.WinForms;

public void Form1_Load(object sender, EventArgs e)
{
  initBrowser();
}

public async void initBrowser()
{
  await webView21.EnsureCoreWebView2Async(null);
  webView21.CoreWebView2.Navigate("https://meet.google.com");
}

Everything, other code and settings etc. are exactly at default values.

And one very strange thing is that at first this code worked perfectly fine, but then once I ran again my project I got this error.

I tred to found something from the internet, but everything info about these I found not worked for me or was too hard to understand... :(

Can someone please help me!

Things I have tried:

Changing the code

Reinstalling the nuget package

Using different (older) versions of the nuget package

Creating new clear project

Disabling firewall

Fixing Microsoft Edge WebView2 Runtime from Control Panel

Changing network

************** Exception Text **************
System.Runtime.InteropServices.COMException (0x8007139F): The group or resource is not in the state required to perform the requested operation. (0x8007139F)
   at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode)
   at Microsoft.Web.WebView2.Core.CoreWebView2Environment.CreateCoreWebView2ControllerAsync(IntPtr ParentWindow)
   at Microsoft.Web.WebView2.WinForms.WebView2.InitCoreWebView2Async(CoreWebView2Environment environment)
   at WebViewSample.Form1.InitBrowser() in C:\Users\NearEternal\Visual Studio 2022\WebViewSample\Form1.cs:line 98
   at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__128_0(Object state)


************** Loaded Assemblies **************
System.Private.CoreLib
    Assembly Version: 6.0.0.0
    Win32 Version: 6.0.422.16404
    CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.4/System.Private.CoreLib.dll
----------------------------------------
WebViewSample
    Assembly Version: 1.0.0.0
    Win32 Version: 1.0.0.0
    CodeBase: file:///C:/Users/NearEternal/Visual%20Studio%202022/WebViewSample/bin/Debug/net6.0-windows/WebViewSample.dll
----------------------------------------
System.Runtime
    Assembly Version: 6.0.0.0
    Win32 Version: 6.0.422.16404
    CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.4/System.Runtime.dll
----------------------------------------
System.Windows.Forms
    Assembly Version: 6.0.2.0
    Win32 Version: 6.0.422.16407
    CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.WindowsDesktop.App/6.0.4/System.Windows.Forms.dll
----------------------------------------
System.ComponentModel.Primitives
    Assembly Version: 6.0.0.0
    Win32 Version: 6.0.422.16404
    CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.4/System.ComponentModel.Primitives.dll
----------------------------------------
System.Windows.Forms.Primitives
    Assembly Version: 6.0.2.0
    Win32 Version: 6.0.422.16407
    CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.WindowsDesktop.App/6.0.4/System.Windows.Forms.Primitives.dll
----------------------------------------
System.Runtime.InteropServices
    Assembly Version: 6.0.0.0
    Win32 Version: 6.0.422.16404
    CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.4/System.Runtime.InteropServices.dll
----------------------------------------
System.Drawing.Primitives
    Assembly Version: 6.0.0.0
    Win32 Version: 6.0.422.16404
    CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.4/System.Drawing.Primitives.dll
----------------------------------------
System.Collections.Specialized
    Assembly Version: 6.0.0.0
    Win32 Version: 6.0.422.16404
    CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.4/System.Collections.Specialized.dll
----------------------------------------
System.Threading
    Assembly Version: 6.0.0.0
    Win32 Version: 6.0.422.16404
    CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.4/System.Threading.dll
----------------------------------------
System.Diagnostics.TraceSource
    Assembly Version: 6.0.0.0
    Win32 Version: 6.0.422.16404
    CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.4/System.Diagnostics.TraceSource.dll
----------------------------------------
System.Collections
    Assembly Version: 6.0.0.0
    Win32 Version: 6.0.422.16404
    CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.4/System.Collections.dll
----------------------------------------
System.Drawing.Common
    Assembly Version: 6.0.0.0
    Win32 Version: 6.0.422.16404
    CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.WindowsDesktop.App/6.0.4/System.Drawing.Common.dll
----------------------------------------
System.Resources.Extensions
    Assembly Version: 6.0.0.0
    Win32 Version: 6.0.422.16404
    CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.WindowsDesktop.App/6.0.4/System.Resources.Extensions.dll
----------------------------------------
System.Memory
    Assembly Version: 6.0.0.0
    Win32 Version: 6.0.422.16404
    CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.4/System.Memory.dll
----------------------------------------
System.Drawing
    Assembly Version: 6.0.2.0
    Win32 Version: 6.0.422.16407
    CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.WindowsDesktop.App/6.0.4/System.Drawing.dll
----------------------------------------
Microsoft.Win32.Primitives
    Assembly Version: 6.0.0.0
    Win32 Version: 6.0.422.16404
    CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.4/Microsoft.Win32.Primitives.dll
----------------------------------------
System.ComponentModel.EventBasedAsync
    Assembly Version: 6.0.0.0
    Win32 Version: 6.0.422.16404
    CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.4/System.ComponentModel.EventBasedAsync.dll
----------------------------------------
System.Threading.Thread
    Assembly Version: 6.0.0.0
    Win32 Version: 6.0.422.16404
    CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.4/System.Threading.Thread.dll
----------------------------------------
Accessibility
    Assembly Version: 4.0.0.0
    Win32 Version: 6.0.422.16407
    CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.WindowsDesktop.App/6.0.4/Accessibility.dll
----------------------------------------
Microsoft.Web.WebView2.WinForms
    Assembly Version: 1.0.1210.30
    Win32 Version: 1.0.1210.30
    CodeBase: file:///C:/Users/NearEternal/Visual%20Studio%202022/WebViewSample/bin/Debug/net6.0-windows/Microsoft.Web.WebView2.WinForms.dll
----------------------------------------
Microsoft.Web.WebView2.Core
    Assembly Version: 1.0.1210.30
    Win32 Version: 1.0.1210.30
    CodeBase: file:///C:/Users/NearEternal/Visual%20Studio%202022/WebViewSample/bin/Debug/net6.0-windows/Microsoft.Web.WebView2.Core.dll
----------------------------------------
mscorlib
    Assembly Version: 4.0.0.0
    Win32 Version: 6.0.422.16404
    CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.4/mscorlib.dll
----------------------------------------
System.ComponentModel.TypeConverter
    Assembly Version: 6.0.0.0
    Win32 Version: 6.0.422.16404
    CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.4/System.ComponentModel.TypeConverter.dll
----------------------------------------
System.Numerics.Vectors
    Assembly Version: 6.0.0.0
    Win32 Version: 6.0.422.16404
    CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.4/System.Numerics.Vectors.dll
----------------------------------------
Microsoft.Win32.SystemEvents
    Assembly Version: 6.0.0.0
    Win32 Version: 6.0.422.16404
    CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.WindowsDesktop.App/6.0.4/Microsoft.Win32.SystemEvents.dll
----------------------------------------
System.Collections.Concurrent
    Assembly Version: 6.0.0.0
    Win32 Version: 6.0.422.16404
    CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.4/System.Collections.Concurrent.dll
----------------------------------------
System.ComponentModel
    Assembly Version: 6.0.0.0
    Win32 Version: 6.0.422.16404
    CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.4/System.ComponentModel.dll
----------------------------------------
System.Private.Uri
    Assembly Version: 6.0.0.0
    Win32 Version: 6.0.422.16404
    CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.4/System.Private.Uri.dll
----------------------------------------
System.Collections.NonGeneric
    Assembly Version: 6.0.0.0
    Win32 Version: 6.0.422.16404
    CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.4/System.Collections.NonGeneric.dll
----------------------------------------
System.Runtime.CompilerServices.Unsafe
    Assembly Version: 6.0.0.0
    Win32 Version: 6.0.422.16404
    CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.4/System.Runtime.CompilerServices.Unsafe.dll
----------------------------------------
System.Threading.Tasks
    Assembly Version: 6.0.0.0
    Win32 Version: 6.0.422.16404
    CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.4/System.Threading.Tasks.dll
----------------------------------------
System.Runtime.Extensions
    Assembly Version: 6.0.0.0
    Win32 Version: 6.0.422.16404
    CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.4/System.Runtime.Extensions.dll
----------------------------------------
System.Threading.ThreadPool
    Assembly Version: 6.0.0.0
    Win32 Version: 6.0.422.16404
    CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.4/System.Threading.ThreadPool.dll
----------------------------------------
System.Runtime.Loader
    Assembly Version: 6.0.0.0
    Win32 Version: 6.0.422.16404
    CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.4/System.Runtime.Loader.dll
----------------------------------------
System.Diagnostics.StackTrace
    Assembly Version: 6.0.0.0
    Win32 Version: 6.0.422.16404
    CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.4/System.Diagnostics.StackTrace.dll
----------------------------------------
System.Reflection.Metadata
    Assembly Version: 6.0.0.0
    Win32 Version: 6.0.422.16404
    CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.4/System.Reflection.Metadata.dll
----------------------------------------
System.Collections.Immutable
    Assembly Version: 6.0.0.0
    Win32 Version: 6.0.422.16404
    CodeBase: file:///C:/Program%20Files/dotnet/shared/Microsoft.NETCore.App/6.0.4/System.Collections.Immutable.dll
----------------------------------------

************** JIT Debugging **************

Importance

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

Runtime Channel

Stable release (WebView2 Runtime)

Runtime Version

1.0.2151.40

SDK Version

1.0.2151.40

Framework

Winforms

Operating System

Windows 10

OS Version

19045.3693

Repro steps

It seems that if I change the solution this error appears and this might be some kind of cache error. So if I took Microosft's Webview2 Sample Repo, it worked for a while, but when I removed one other project from this solution, it also stops working.

Repros in Edge Browser

Not Applicable

Regression

Don't know

Last working version (if regression)

No response

@kodybrown
Copy link

kodybrown commented Dec 7, 2023

I get this error also.

For me it worked yesterday.
But, I finally decided to let Windows update to 22H2 (from 21H1) just now.
And now my apps are broken.
That's what I get for allowing updates I guess... 🙄

The only option for Microsoft Edge WebView2 Runtime (in Control Panel appwiz.cpl) is "Repair".
The only option for it in Apps & features (Settings dialog) is "Modify", which only allows "Modify".
I did that and it still doesn't work.
I've tried many other suggestions from numerous sources without success.

I would love some additional suggestions!
Preferably ones that don't involve me re-installing back to a clean Windows 10 and disabling updates. Again. 😉

@kodybrown
Copy link

kodybrown commented Dec 7, 2023

I should note that this error may go away for me.
Apparently, there are more updates still needed. 🙄

Reboot number 4 coming up.
Maybe its reboot 5, I lost track... 😉

I will update here if the error gets resolved by an update.

@kodybrown
Copy link

There doesn't seem to be any more updates.
No change. I still get the error... 😟

image

@vbryh-msft
Copy link
Contributor

vbryh-msft commented Dec 7, 2023

Here is another thread about 0x8007139F error. The most probable root cause of the issue is that there is already another browser process running in the same user data folder with incompatible configuration, i.e. different browser arguments(AdditionalBrowserArguments). You should be able to check it in Process Explorer or some other app. Also can try to start in new clean user data folder to confirm that it is the issue.

@kodybrown
Copy link

Thank you for the suggestion! 🙂
I'll keep an eye on that thread as well!

I ran into that situation earlier in development (already another browser process running in the same user data folder)
and solved it by using a custom/unique user data directory that is specific to my app.

For good measure, I closed all instances of (any) browsers and most apps, just in case.
I then also tried explicitly setting the profile and user-data-dir command-line arguments.
Same error.

@kodybrown
Copy link

@vbryh-msft, I tried two of the samples you recommended in the other thread, with the same results. Lunch is over, I'll check back in tonight and try some more..

@vbryh-msft
Copy link
Contributor

vbryh-msft commented Dec 8, 2023

@kodybrown from your traces the webview2 runtime can not be started because of incompatible DPI awareness. The expectation in traces is that it should be 2 but the ask is to have DPI awareness as 1. Could you check what is the value of __COMPAT_LAYER env var when host app is started and what is DPI awareness of host app?

@carrie-battaglia
Copy link

Is there a solution? I am having the same error with the sample apps. System.Runtime.InteropServices.COMException: 'The group or resource is not in the state required to perform the requested operation. (0x8007139F)'

@vbryh-msft
Copy link
Contributor

Hi @carrie-battaglia - you would need to understand why it happens in order to fix it. Have you read the threads how to troubleshoot?

@carrie-battaglia
Copy link

carrie-battaglia commented Feb 7, 2024 via email

@vbryh-msft
Copy link
Contributor

@carrie-battaglia - can you collect traces when you repro it?

@LK-Global
Copy link

I have seen this error; as I found that a second attempt to create the environment after closing my application always worked; I implemented a try catch with a 5 second delay and then retried to create the environment.

The retry has worked...

@carrie-battaglia
Copy link

I followed the directions for the trace and found that I have Microsoft Teams running in the background (which has multiple msedgewebview2.exe's in task manager). I don't use that app - maybe it started from some update. Once I quit that app, the sample ran without the exception.

So the issue now is, how will my webview2 component work if a user has anything else running that uses webview2? I'm assuming this might have to do with setting a unique environment but I have not gotten that to work correctly.

I submitted this issue a few months ago: #4163 but have not gotten any feedback (during a build, my VS project launches msedgewebview2.exe and does not clean them up. When I run the project, I get the exception 'The group or resource is not in the state required to perform the requested operation. (0x8007139F)').

@vbryh-msft
Copy link
Contributor

@carrie-battaglia sounds like you have user data folder override somewhere in you system (WEBVIEW2_USER_DATA_FOLDER env var or reg key) and each app tries to attach to browser started from that UDF. UDF overrides are intended to be used for debugging purpose only. Here is some reading about process model. Hope it helps.

@scorpion3399
Copy link

I had the same problem however the Exception did not have the code 0x8007139F after it (maybe due to localization in VS2022 but the message was the same) and the exception was thrown every time I attempted to call WebView.EnsureCoreWebView2Async() breaking an important feature in my app. It was suggested to me to delete the bin and obj folders in the project and build the solution again. For me it was MySolution/MyApp.Desktop/bin and MySolution/MyApp.Desktop/obj.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants