5

We are using webview2 to launch browser window. At design time webview2 is working fine and we see browser window, but at runtime webview2 is not getting initialized. For the design time only x64 Webview2Loader.dll working, but x64 webview2Loader.dll is not working for runtime, I manually copied x86 Webview2Loader.dll into nuget folder - still it is throwing same exception and not able to load Webview2Loader.dll.
.NET Framework = .net5
Webview2 version = 1.0.1072.54

"message": "System.DllNotFoundException: Unable to load DLL 'WebView2Loader.dll' or one of its dependencies: The specified module could not be found. (0x8007007E)
  at Microsoft.Web.WebView2.Core.CoreWebView2Environment.CreateCoreWebView2EnvironmentWithOptions(String browserExecutableFolder, String userDataFolder, ICoreWebView2EnvironmentOptions options, ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler environment_created_handler)
  at Microsoft.Web.WebView2.Core.CoreWebView2Environment.CreateAsync(String browserExecutableFolder, String userDataFolder, CoreWebView2EnvironmentOptions options)
  at Microsoft.Web.WebView2.Wpf.WebView2.<>c__DisplayClass27_0.<<EnsureCoreWebView2Async>g__Init|0>d.MoveNext()
seef07
  • 125
  • 2
  • 13

2 Answers2

1

As written in the documentation in this paragraph Files to ship with the app the dlls of webview2 must be present in the application folder.

For .NET managed apps, you also need to include the WebView2 .NET assemblies for the core WebView2 functionality (Microsoft.Web.WebView2.Core.dll) and for the WPF/WinForms-specific functionality (Microsoft.Web.WebView2.Winforms.dll or Microsoft.Web.WebView2.WPF.dll).

Example managed app folder structure:

\<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)
renzo
  • 85
  • 1
  • 9
1

Here in February 2023 I encounter this same DllNotFound error while recently debugging a WPF project that was calling a WebView2 method. The solution was slightly different to the one given above so I'm posting it here.

I found a report of a WebView2 regression in January of 2022 that reports DllNotFound: https://github.com/MicrosoftEdge/WebView2Feedback/issues/2046 ...however my machine had the latest version of the WebView2 DLL installed in the OS; so not quite the problem.

For some reason the version of Microsoft.Web.WebView2 NuGet package in my program was v1.0.1518.46. However, the latest WebView2 NuGet package was v1.0.1587.40.

Just upgrading the program's WebView2 NuGet package eliminated the DllNotFound exception and the program to run normally.

rfreytag
  • 955
  • 1
  • 8
  • 24