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

AddBrowserExtensionAsync Error #4977

Closed
bearsInformation opened this issue Dec 6, 2024 · 6 comments
Closed

AddBrowserExtensionAsync Error #4977

bearsInformation opened this issue Dec 6, 2024 · 6 comments
Assignees
Labels
bug Something isn't working

Comments

@bearsInformation
Copy link

What happened?

An error occurs when using AddBrowserExtensionAsync.

error

System.Reflection.TargetInvocationException
  HResult=0x80131604
  Message=Exception has been thrown by the target of an invocation.
  Source=mscorlib
  Stack trace:
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) in System.Reflection\RuntimeMethodInfo.cs:line 625
   at System.Delegate.DynamicInvokeImpl(Object[] args) in System\Delegate.cs:line 158
   at System.Windows.Forms.Control.InvokeMarshaledCallbackDo(ThreadMethodEntry tme) in System.Windows.Forms\Control.cs:line 10635
   at System.Windows.Forms.Control.InvokeMarshaledCallbackHelper(Object obj) in System.Windows.Forms\Control.cs:line 10597
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) in System.Threading\ExecutionContext.cs:line 518
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) in System.Threading\ExecutionContext.cs:line 489
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) in System.Threading\ExecutionContext.cs:line 482
   at System.Windows.Forms.Control.InvokeMarshaledCallback(ThreadMethodEntry tme) in System.Windows.Forms\Control.cs:line 10580
   at System.Windows.Forms.Control.InvokeMarshaledCallbacks() in System.Windows.Forms\Control.cs:line 10657
   at System.Windows.Forms.Control.WndProc(Message& m) in System.Windows.Forms\Control.cs:line 15870
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) in System.Windows.Forms\Control.cs:line 135
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) in System.Windows.Forms\Control.cs:line 163
   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) in System.Windows.Forms\NativeWindow.cs:line 743
   at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
   at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData) in System.Windows.Forms\Application.cs:line 304
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) in System.Windows.Forms\Application.cs:line 1235
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context) in System.Windows.Forms\Application.cs:line 1151
   at System.Windows.Forms.Application.Run(Form mainForm) in System.Windows.Forms\Application.cs:line 3091

  This exception was first thrown by this call stack 
    Microsoft.Web.WebView2.Core.CoreWebView2Profile.AddBrowserExtensionAsync(string) (CoreWebView2Profile.cs in)
    WebView2_TEST_C_.Form1.WebView2_CoreWebView2InitializationCompleted(object, Microsoft.Web.WebView2.Core.CoreWebView2InitializationCompletedEventArgs) (Form1.cs in)
    System.Runtime.CompilerServices.AsyncMethodBuilderCore.ThrowAsync.AnonymousMethod__6_0(object) (AsyncMethodBuilderCore.cs in) was thrown at

Inner Exception 1:
COMException: Class not registered

Class not registered

Importance

Important. My app's user experience is significantly compromised.

Runtime Channel

Stable release (WebView2 Runtime)

Runtime Version

131.0.2903.70

SDK Version

1.0.2903.40

Framework

Winforms

Operating System

Windows 11

OS Version

23H2

Repro steps

code

using Microsoft.Web.WebView2.Core;
using System;

using System.Threading.Tasks;
using System.Windows.Forms;

namespace WebView2_TEST_C_
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private async Task InitializeAsync()
        {
            WebView2.CoreWebView2InitializationCompleted += WebView2_CoreWebView2InitializationCompleted;
            var options = new CoreWebView2EnvironmentOptions();
            options.AreBrowserExtensionsEnabled = true;
            CoreWebView2Environment environment = await CoreWebView2Environment.CreateAsync(null, null, options);
            await WebView2.EnsureCoreWebView2Async(null);
        }

        private async void Form1_Load(object sender, EventArgs e)
        {
            await InitializeAsync();
        }

        private async void WebView2_CoreWebView2InitializationCompleted(object sender, Microsoft.Web.WebView2.Core.CoreWebView2InitializationCompletedEventArgs e)
        {
            // Operation confirmed on edge
            var path = @"<%userprofile%>AppData\Local\Microsoft\Edge\User Data\Default\Extensions\xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\1.0.0.0_0";
            var extension = await WebView2.CoreWebView2.Profile.AddBrowserExtensionAsync(path);
        }
    }
}

Repros in Edge Browser

No, issue does not reproduce in the corresponding Edge version

Regression

Don't know

Last working version (if regression)

No response

@bearsInformation bearsInformation added the bug Something isn't working label Dec 6, 2024
@sivMSFT
Copy link

sivMSFT commented Dec 9, 2024

Hey @bearsInformation, ensure that the WebView2 runtime and SDK versions are compatible.

@bearsInformation
Copy link
Author

https://learn.microsoft.com/en-us/microsoft-edge/webview2/release-notes/?tabs=dotnetcsharp

1.0.2903.40
Release Date: November 18, 2024
NuGet package for WebView2 SDK 1.0.2903.40
For full API compatibility, this Release version of the WebView2 SDK requires WebView2 Runtime version 131.0.2903.40 or higher.

131.0.2903.70 > 131.0.2903.40
Runtime and SDK usage requirements are met

@bearsInformation
Copy link
Author

Runtime Version

131.0.2903.70

SDK Version

1.0.2903.39 NG
1.0.2849.39 NG
1.0.2792.45 NG

@sivMSFT
Copy link

sivMSFT commented Dec 10, 2024

Hi @bearsInformation, we tried to repro using the given code by you.
We didn't find any error; the code was running smooth.

Could you check if you are using the updated Windows SDK?

@bearsInformation
Copy link
Author

About SDKs

 Visual Studio 2022
 NuGet Package Manager -> Manage NuGet Packages for Solution
Check 「Latest stable version 1.0.2903.40」 in

Project folder
 ... \bin\Debug\runtimes\win-x64\native\WebView2Loader.dll
File Version
 「1.0.2903.40

https://www.nuget.org/packages/Microsoft.Web.WebView2/1.0.2903.40
PM> NuGet\Install-Package Microsoft.Web.WebView2 -Version 1.0.2903.40
Same result.

About Runtime

「Microsoft Edge WebView2 Runtime」 install the latest version using 「Microsoft Edge」

Microsoft Edge
「Version 131.0.2903.86 (official build) (64bit)」

Registry
HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\EdgeUpdate\Clients{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}
 Iocation 「C:\Program Files (x86)\Microsoft\EdgeWebView\Application」
 pv 「131.0.2903.86

Runtime folder
 「C:\Program Files (x86)\Microsoft\EdgeWebView\Application\131.0.2903.86\msedge.exe」
File Version.
 「131.0.2903.86

Due to an increase in the version of Microsoft Edge from the previous
Changed to 131.0.2903.70 -> 131.0.2903.86

@bearsInformation
Copy link
Author

Sorry, there was a mistake in my code.
The correct code is here.

using Microsoft.Web.WebView2.Core;
using System;

using System.Threading.Tasks;
using System.Windows.Forms;

namespace WebView2_TEST_C_
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private async Task InitializeAsync()
        {
            WebView2.CoreWebView2InitializationCompleted += WebView2_CoreWebView2InitializationCompleted;
            var options = new CoreWebView2EnvironmentOptions();
            options.AreBrowserExtensionsEnabled = true;
            CoreWebView2Environment environment = await CoreWebView2Environment.CreateAsync(null, null, options);
            await WebView2.EnsureCoreWebView2Async(environment);
        }

        private async void Form1_Load(object sender, EventArgs e)
        {
            await InitializeAsync();
        }

        private async void WebView2_CoreWebView2InitializationCompleted(object sender, Microsoft.Web.WebView2.Core.CoreWebView2InitializationCompletedEventArgs e)
        {
            // Operation confirmed on edge
            var path = @"<%userprofile%>AppData\Local\Microsoft\Edge\User Data\Default\Extensions\xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\1.0.0.0_0";
            var extension = await WebView2.CoreWebView2.Profile.AddBrowserExtensionAsync(path);
        }
    }
}

await WebView2.EnsureCoreWebView2Async(null); // NG
await WebView2.EnsureCoreWebView2Async(environment); // OK

The cause was accessing it when the Environment had not yet been initialized (initial settings of the environment folder).
Although it was registered correctly, another problem occurred, so I will discuss that separately.

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

3 participants