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

WebView2 Initialization Error in WinPE x64 #4951

Open
Abithk7-1 opened this issue Nov 27, 2024 Discussed in #4947 · 8 comments
Open

WebView2 Initialization Error in WinPE x64 #4951

Abithk7-1 opened this issue Nov 27, 2024 Discussed in #4947 · 8 comments

Comments

@Abithk7-1
Copy link

Discussed in #4947

Originally posted by Abithk7-1 November 26, 2024
I'm experiencing an issue with WebView2 initialization in our WinPE x64 environment.

The error I'm encountering is:
System.Runtime.InteropServices.COMException (0x80080005): Server execution failed (Exception from HRESULT: 0x8008005 (CO_E_SERVER_EXEC_FAILURE)) at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo) at Microsoft.Web.WebView2.Core.CoreWebView2Environment.d__102.MoveNext()

Environment:
WinPE x64
Framework: 4.8.1
I'm using the following nuget libraries:

  • Microsoft.Web.WebView2.Core.dll
  • Microsoft.Web.WebView2.Winforms.dll
  • Microsoft.Web.WebView2.WPF.dll
    The WebView2 Fixed Version Runtime binaries I'm using is:
  • Microsoft.WebView2.FixedVersionRuntime.130.0.2849.56.x64

My code for initializing WebView2 is as follows:
string exeLocation = AppDomain.CurrentDomain.BaseDirectory;
string webView2Folder = Path.Combine(exeLocation, "WebView2x64");
string logFilePath = Path.Combine(exeLocation, "WebView2Log.txt");
string userDataFolder = Path.Combine(exeLocation, "UserData");

        try
        {

            // Create WebView2 environment with logging enabled
            var environment = await CoreWebView2Environment.CreateAsync(
                browserExecutableFolder: webView2Folder,
                userDataFolder: userDataFolder,
                options: new CoreWebView2EnvironmentOptions("--enable-logging --v=1"));
            // Initialize WebView2 with the environment
            await webView.EnsureCoreWebView2Async(environment);
            webView.CoreWebView2.Navigate(Url);
            // Log a success message
            Log( "WebView2 initialized successfully.");
        }
        catch (Exception ex)
        {
            // Log any initialization errors
            Log($"Error initializing WebView2: {ex.ToString()}");
        }

The folder structure for the WebView2 libraries is as follows:

<myApp>
\Microsoft.Web.WebView2.Core.dll
\Microsoft.Web.WebView2.Winforms.dll
\Microsoft.Web.WebView2.WPF.dll
\runtimes
\win-arm64\native\WebView2Loader.dll (arm64)
\win-x64\native\WebView2Loader.dll (x64)
\win-x86\native\WebView2Loader.dll (x86)

  </div>
@icnocop
Copy link

icnocop commented Jan 10, 2025

See #4293

@icnocop
Copy link

icnocop commented Jan 14, 2025

Is the log file created (--enable-logging --v=1)?
If so, what are the contents?

@Abithk7-1
Copy link
Author

Is the log file created (--enable-logging --v=1)? If so, what are the contents?
@icnocop
The log file was not created.

@icnocop
Copy link

icnocop commented Jan 15, 2025

Did you try setting --enable-logging=stderr and/or --log-file=X:\logfile.txt ?

Documentation reference: https://www.chromium.org/for-testers/enable-logging/

Edit:
https://chromium.googlesource.com/playground/chromium-org-site/+/refs/heads/main/for-testers/enable-logging/index.md

--enable-logging=stderr (not available on Windows)

@Abithk7-1
Copy link
Author

Did you try setting --enable-logging=stderr and/or --log-file=X:\logfile.txt ?

Documentation reference: https://www.chromium.org/for-testers/enable-logging/

@icnocop i tried with --log-file=X:\logfile.txt
but it still did not create any log file for me

@icnocop
Copy link

icnocop commented Jan 15, 2025

Are the WebView2 runtime libraries in the "WebView2x64" folder?

string exeLocation = AppDomain.CurrentDomain.BaseDirectory;
string webView2Folder = Path.Combine(exeLocation, "WebView2x64");

But you mentioned:

The folder structure for the WebView2 libraries is as follows:
<myApp>
\Microsoft.Web.WebView2.Core.dll
\Microsoft.Web.WebView2.Winforms.dll
\Microsoft.Web.WebView2.WPF.dll
\runtimes
\win-arm64\native\WebView2Loader.dll (arm64)
\win-x64\native\WebView2Loader.dll (x64)
\win-x86\native\WebView2Loader.dll (x86)

@Abithk7-1
Copy link
Author

Are the WebView2 runtime libraries in the "WebView2x64" folder?

string exeLocation = AppDomain.CurrentDomain.BaseDirectory;
string webView2Folder = Path.Combine(exeLocation, "WebView2x64");

But you mentioned:

The folder structure for the WebView2 libraries is as follows:
<myApp>
\Microsoft.Web.WebView2.Core.dll
\Microsoft.Web.WebView2.Winforms.dll
\Microsoft.Web.WebView2.WPF.dll
\runtimes
\win-arm64\native\WebView2Loader.dll (arm64)
\win-x64\native\WebView2Loader.dll (x64)
\win-x86\native\WebView2Loader.dll (x86)

I did copy the structure and forgot to mention the binaries which i have added from webview2 Fixed Runtime

<myApp>
     \Microsoft.Web.WebView2.Core.dll
     \Microsoft.Web.WebView2.Winforms.dll
     \Microsoft.Web.WebView2.WPF.dll
\runtimes
     \win-arm64\native\WebView2Loader.dll (arm64)
     \win-x64\native\WebView2Loader.dll (x64)
     \win-x86\native\WebView2Loader.dll (x86)
\WebView2x64 (Fixed Version)
     \msedgewebview2.exe, msedge.dll, etc

Please let me know, if i need to make any changes to the folder structure.

@icnocop
Copy link

icnocop commented Jan 16, 2025

You can try to hook into the BlazorWebViewInitializing event and try to enable logging in the CoreWebView2 environment before the WebView2 is initialized and then you can also try to hook into the BlazorWebViewInitialized event to log the details of the initialized CoreWebView2 environment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants