MicrosoftEdge / MicrosoftEdge/WebView2Feedback

[Problem/Bug]: How to influence which WebView2Loader.dll is used by WebView2's managed code

Open
#4,693 0 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
PowerShell
Stars
526
Forks
67
PR merge metrics
No merged PRs in 30d

Description

What happened?

Hi, we have a Visual Studio 2022 extension that we've recently added the NuGet package Microsoft.Web.WebView2 to. We've recently learned that we have to be careful about what API calls we use, because not every API call is supported by all versions of WebView2.

We are calling a function GetAvailableBrowserVersionString, and GetAvailableBrowserVersionString then calls out to unmanaged code in WebView2Loader.dll. There are two overloads to this function:

GetAvailableBrowserVersionString(string browserExecutableFolder)

This makes a pinvoke call to:

[DllImport("WebView2Loader.dll")]
internal static extern int GetAvailableCoreWebView2BrowserVersionString([In][MarshalAs(UnmanagedType.LPWStr)] string browserExecutableFolder, [MarshalAs(UnmanagedType.LPWStr)] ref string versionInfo);

GetAvailableBrowserVersionString(string browserExecutableFolder, CoreWebView2EnvironmentOptions environmentOptions)

This makes a pinvoke call to:

[DllImport("WebView2Loader.dll")]
internal static extern int GetAvailableCoreWebView2BrowserVersionStringWithOptions([In][MarshalAs(UnmanagedType.LPWStr)] string browserExecutableFolder, ICoreWebView2EnvironmentOptions options, [MarshalAs(UnmanagedType.LPWStr)] ref string versionInfo);

Where things get interesting is that Visual Studio will sometimes have both its own copy of WebView2Loader.dll and our extension's copy of WebView2Loader.dll loaded. Even when we call CoreWebView2Environment.SetLoaderDllFolderPath, there doesn't appear to be a deterministic way to influence which dll is used for the DllImport call when we call GetAvailableBrowserVersionString. When the Visual Studio copy of the dll happens to be used, an "Unable to find an entry point named '?' in DLL 'WebView2Loader.dll'" exception is raised. When our extension's copy of the dll is used, things work as expected.

We're switching to use the overload that supports older versions. Is there something I'm missing that relates to how to control which dll is used for the pinvoke calls? Have you got any other guidance to share (aside from "check the compatibility version of each API call")?

Importance

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

Runtime Channel

Stable release (WebView2 Runtime)

Runtime Version

126.0.2592.102

SDK Version

1.0.2478.35

Framework

WPF

Operating System

Windows 10, Windows 11

OS Version

No response

Repro steps
  • use Visual Studio in a way that causes it to load its own copy of webview2 dlls first (17.10.4 appears to use 1.0.2151.40)
  • then use my extension in a way that causes it to load its copy of webview dlls second (we're using 1.0.2478.35)
  • try to call the GetAvailableBrowserVersionString() or GetAvailableBrowserVersionString(String, CoreWebView2EnvironmentOptions) overloads from the extension
  • get Unable to find an entry point named '?' in DLL 'WebView2Loader.dll` exception
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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No repository files or tests are named. Reproduce the issue using Visual Studio 17.10.4, SDK 1.0.2478.35, and the two WebView2Loader.dll versions described; then investigate how SetLoaderDllFolderPath and the managed DllImport calls select the loaded DLL. Done means documenting deterministic guidance or identifying a supported fix for the loader conflict.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
api, desktop
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.