【问题标题】:System.DllNotFoundException: Unable to load DLL 'WebView2Loader.dll' The specified module could not be found. (0x8007007E)System.DllNotFoundException: 无法加载 DLL \'WebView2Loader.dll\' 找不到指定的模块。 (0x8007007E)
【发布时间】:2023-02-22 06:41:57
【问题描述】:

我们正在使用 webview2 启动浏览器窗口。 在设计时 webview2 工作正常,我们看到浏览器窗口,但在运行时 webview2 没有被初始化。对于设计时只有 x64 Webview2Loader.dll 工作,但 x64 webview2Loader.dll 在运行时不工作,我手动将 x86 Webview2Loader.dll 复制到 nuget 文件夹中 - 它仍然抛出相同的异常并且无法加载 Webview2Loader.dll。
.NET 框架 = .net5
Webview2 版本 = 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()

【问题讨论】:

    标签: .net-5 webview2


    【解决方案1】:

    正如本段Files to ship with the app 的文档中所写,webview2 的 dll 必须存在于应用程序文件夹中。

    对于 .NET 托管应用程序,您还需要包含 WebView2 .NET 核心 WebView2 功能的程序集 (Microsoft.Web.WebView2.Core.dll) 和特定于 WPF/WinForms 功能(Microsoft.Web.WebView2.Winforms.dll 或 Microsoft.Web.WebView2.WPF.dll)。

    托管应用程序文件夹结构示例:

    <myApp>
        Microsoft.Web.WebView2.Core.dll
        Microsoft.Web.WebView2.Winforms.dll
        Microsoft.Web.WebView2.WPF.dll
        
    untimes
            win-arm64
    ativeWebView2Loader.dll (arm64)
            win-x64
    ativeWebView2Loader.dll (x64)
            win-x86
    ativeWebView2Loader.dll (x86)
    

    【讨论】:

      【解决方案2】:

      2023 年 1 月,我在最近调试调用 WebView2 方法的 WPF 项目时遇到了同样的 DllNotFound 错误。该解决方案与上面给出的解决方案略有不同,因此我将其发布在这里。

      我在 2022 年 1 月发现了一份 WebView2 回归报告,报告 DllNotFound:https://github.com/MicrosoftEdge/WebView2Feedback/issues/2046 ...但是我的机器在操作系统中安装了最新版本的 WebView2 DLL;所以问题不大。

      由于某种原因,我程序中 Microsoft.Web.WebView2 NuGet 包的版本是 v1.0.1518.46。但是,最新的 WebView2 NuGet 包是 v1.0.1587.40。

      只需升级程序的WebView2 NuGet包,即可消除DllNotFound异常,程序正常运行。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2022-01-10
        • 2019-03-08
        • 1970-01-01
        • 1970-01-01
        • 2012-02-18
        • 2019-12-24
        • 2020-02-18
        • 1970-01-01
        相关资源
        最近更新 更多