MicrosoftEdge / WebView2Feedback

Feedback and discussions about Microsoft Edge WebView2
https://aka.ms/webview2
437 stars 51 forks source link

[Problem/Bug]: Microsoft.Web.WebView2 throws an System.Runtime.InteropServices.COMException (0x8007139F) randomly #4218

Open NearEternal opened 9 months ago

NearEternal commented 9 months ago

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 commented 9 months ago

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 commented 9 months ago

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 commented 9 months ago

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

image

vbryh-msft commented 9 months ago

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 commented 9 months ago

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 commented 9 months ago

@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 commented 9 months ago

@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 commented 7 months ago

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 commented 7 months ago

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 commented 7 months ago

I have tried many changes – is there some info you want me to collect that will help? Thank you

From: vbryh-msft @.> Sent: Wednesday, February 7, 2024 4:15 PM To: MicrosoftEdge/WebView2Feedback @.> Cc: Carrie Battaglia @.>; Mention @.> Subject: [External] : Re: [MicrosoftEdge/WebView2Feedback] [Problem/Bug]: Microsoft.Web.WebView2 throws an System.Runtime.InteropServices.COMException (0x8007139F) randomly (Issue #4218)

Hi @carrie-battagliahttps://urldefense.com/v3/__https:/github.com/carrie-battaglia__;!!ACWV5N9M2RV99hQ!O9U0kLv0-uxEPfokfPB5Iclqa80ZqAgY_tsKfxOp0qI3GulzpbFr8hZ0f7WN_VqJktvhAcZm6vlk82NChV-rY4GWyKgjYw$ - you would need to understand why it happens in order to fix it. Have you read the threads how to troubleshoot?

— Reply to this email directly, view it on GitHubhttps://urldefense.com/v3/__https:/github.com/MicrosoftEdge/WebView2Feedback/issues/4218*issuecomment-1932927167__;Iw!!ACWV5N9M2RV99hQ!O9U0kLv0-uxEPfokfPB5Iclqa80ZqAgY_tsKfxOp0qI3GulzpbFr8hZ0f7WN_VqJktvhAcZm6vlk82NChV-rY4GJYcjMlg$, or unsubscribehttps://urldefense.com/v3/__https:/github.com/notifications/unsubscribe-auth/BD5YGTMPUCQBOZUZU5ZYZNLYSPVFZAVCNFSM6AAAAABAJIFUJWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMZSHEZDOMJWG4__;!!ACWV5N9M2RV99hQ!O9U0kLv0-uxEPfokfPB5Iclqa80ZqAgY_tsKfxOp0qI3GulzpbFr8hZ0f7WN_VqJktvhAcZm6vlk82NChV-rY4ENd7kE5g$. You are receiving this because you were mentioned.Message ID: @.***>

vbryh-msft commented 7 months ago

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

LK-Global commented 7 months ago

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 commented 7 months ago

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: https://github.com/MicrosoftEdge/WebView2Feedback/issues/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 commented 7 months ago

@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.