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

Failure to locate/load 'WebView2Loader.dll' when '#' or non-english characters in the path #1236

Closed
leodin61 opened this issue Apr 28, 2021 · 15 comments
Assignees
Labels
bug Something isn't working tracked We are tracking this work internally.

Comments

@leodin61
Copy link

leodin61 commented Apr 28, 2021

Description

When client app is running in a folder containing "#" character in its name, i.e. "C:\Projects\Temp\Debug #317\test.exe"
invoking CoreWebView2Environment.GetAvailableBrowserVersionString() throws:

{"Unable to load DLL 'WebView2Loader.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)"}
Data: {System.Collections.ListDictionaryInternal}
HResult: -2146233052
HelpLink: null
InnerException: null
Message: "Unable to load DLL 'WebView2Loader.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)"
Source: "Microsoft.Web.WebView2.Core"
StackTrace: " at Microsoft.Web.WebView2.Core.CoreWebView2Environment.GetAvailableCoreWebView2BrowserVersionString(String browserExecutableFolder, String& versionInfo)\r\n at Microsoft.Web.WebView2.Core.CoreWebView2Environment.GetAvailableBrowserVersionString(String browserExecutableFolder)\r\n at Nuance.Dma.View.WebView2Ext.IsRuntimeInstalled() in C:\.....\WebView2Ext.cs:line 63"
TargetSite: {Int32 GetAvailableCoreWebView2BrowserVersionString(System.String, System.String ByRef)}
TypeName: ""

Loader lib confirmed to be in place ( C:\Projects\Temp\Debug #317\x86\WebView2Loader.dll )

Removing "#" from the folder name works fine.

Version
SDK: WebView2 v1.0.705.50 (WPF)
Runtime: evergreen runtime "90.0.818.49"
Framework: WPF
OS: Win10

Repro Steps

AB#37110283

@leodin61 leodin61 added the bug Something isn't working label Apr 28, 2021
@champnic
Copy link
Member

Hey @leodin61 - thanks for the bug report! There have been some minor changes to where and how the WebView2Loader.dll is loaded - would you mind trying a newer SDK package to see if that resolves the issue? If not I'm happy to put this bug on our backlog to take a closer look.

@champnic champnic self-assigned this Apr 29, 2021
@gileli121
Copy link

gileli121 commented Nov 19, 2021

@champnic
I found out that when the program path contains non-English characters, you will get this error
And the error is not fixed also in 1.0.1056-prerelease when running the program under a folder with a path that contains non-English characters.

In my case, I used this path:
C:\עברית\Build2

@gileli121
Copy link

@champnic
This issue with non-English characters is very old and I was able to reproduce it even with 1.0.705.50
I could not test older versions because my app will fail to build due to code compatibility issue

@champnic
Copy link
Member

Thanks for the pointer! If that's the issue then I expect this affects all of our SDKs. I've added this bug to our backlog to try and fix.

@champnic champnic added the tracked We are tracking this work internally. label Nov 20, 2021
@champnic champnic changed the title CoreWebView2Environment.GetAvailableBrowserVersionString() exception - fails to locate/load 'WebView2Loader.dll' Failure to locate/load 'WebView2Loader.dll' when '#' or non-english characters in the path Nov 20, 2021
@gileli121
Copy link

gileli121 commented Nov 20, 2021

@champnic
Thanks.
Any idea when it will be fixed?
I tried these workarounds:
Win32Native.AddDllDirectory("\\");
https://docs.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-adddlldirectory

        [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        public static extern int AddDllDirectory(string lpPathName);

And also:
Utils.AddEnvironmentPaths(new[] { "\\" });

        public static void AddEnvironmentPaths(IEnumerable<string> paths)
        {
            var path = new[] {Environment.GetEnvironmentVariable("PATH") ?? string.Empty};

            string newPath = string.Join(Path.PathSeparator.ToString(), path.Concat(paths));

            Environment.SetEnvironmentVariable("PATH", newPath);
        }

I hoped that somehow it will pick it using a relative path that does not depend on non-English chars.
it did not fix it

@champnic
Copy link
Member

Hey @gileli121 - Can you try using SetDllDirectory (also in kernel32.dll) instead of AddDllDirectory?

@champnic
Copy link
Member

I've got the fix getting checked in now - I'll let you know when it's available. Thanks!

@gileli121
Copy link

@champnic
Great!
I wanted to check if SetDllDirectory will work. I did not know that this function exists. I just did not have time last day to check it.
But even if it will work, it is a less good solution for my case because I use multiple DLL directories and not only one.
And I assume that this function will remove all other DLL directories and replace them to one directory.

How did you fixed it?

@champnic
Copy link
Member

When we were calculating the path to the WebView2Loader.dll in our code it was getting put through a new Uri(<path>) which was stripping out the # character from the path. The fix is to use the paths directly.

Ya, sounds like SetDllDirectory probably won't help you here. The other option is to manually LoadLibrary for WebView2Loader.dll yourself. but I would probably wait until the fix is available if you can.

@gileli121
Copy link

@champnic
When the fix will be available?
It is now 10 days since I reported about it

@champnic
Copy link
Member

champnic commented Dec 7, 2021

Hey @gileli121 - The fix will ship with the next prerelease package (it unfortunately missed the recent prerelease), which will probably be in early January. Thanks!

@champnic
Copy link
Member

This is now fixed in the 1.0.1133-prerelease SDK. Thanks!

@Mecanik
Copy link

Mecanik commented Jul 28, 2022

I have the same issue. Once I moved the .exe out of the debug/release folder this message shows. Very weird since there is no such .dll in the first place in the debug/release folders. Any ideas where I can get it?

@Mecanik
Copy link

Mecanik commented Jul 28, 2022

I take one comment back, it seems the .dll is deployed to "runtimes\win-x86\native".

@champnic
Copy link
Member

champnic commented Aug 4, 2022

Hey @Mecanik - Your app needs some WebView2 SDK files shipped with it to function properly. There should be some helpful details here:
https://docs.microsoft.com/en-us/microsoft-edge/webview2/concepts/distribution#files-to-ship-with-the-app

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

No branches or pull requests

4 participants