You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

WinForms NUnit .NET Framework下CefSharp.Core.Runtime加载异常求助

解决.NET Framework 4.8 WinForms NUnit测试项目中CefSharp程序集加载不匹配问题
  • 清理并重建解决方案

    • 右键解决方案选择「清理解决方案」
    • 删除所有项目下的bin和obj文件夹
    • 右键解决方案选择「重建解决方案」
    • 清理NuGet缓存:打开Package Manager Console执行dotnet nuget locals all --clear,或通过Visual Studio「工具->NuGet包管理器->包管理器设置」清理缓存
  • 配置程序集绑定重定向
    在测试项目的App.config中添加或更新CefSharp相关绑定规则,确保版本统一为121.3.130.0:

    <runtime>
      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
          <assemblyIdentity name="CefSharp.Core.Runtime" publicKeyToken="40c4b6fc221f4138" culture="neutral" />
          <bindingRedirect oldVersion="0.0.0.0-121.3.130.0" newVersion="121.3.130.0" />
        </dependentAssembly>
        <dependentAssembly>
          <assemblyIdentity name="CefSharp.Common" publicKeyToken="40c4b6fc221f4138" culture="neutral" />
          <bindingRedirect oldVersion="0.0.0.0-121.3.130.0" newVersion="121.3.130.0" />
        </dependentAssembly>
        <dependentAssembly>
          <assemblyIdentity name="CefSharp.WinForms" publicKeyToken="40c4b6fc221f4138" culture="neutral" />
          <bindingRedirect oldVersion="0.0.0.0-121.3.130.0" newVersion="121.3.130.0" />
        </dependentAssembly>
      </assemblyBinding>
    </runtime>
    
  • 统一项目平台目标

    • 右键测试项目选择「属性->生成」,将「平台目标」设置为x64或x86(CefSharp不支持AnyCPU,需与引用包的平台一致)
    • 同步设置解决方案平台为对应的x64/x86
  • 检查NuGet包引用一致性

    • 若使用packages.config格式,确认所有CefSharp相关包版本均为121.3.130,无混合版本
    • 若使用PackageReference格式,通过「管理NuGet程序包」确认CefSharp.Common、CefSharp.OffScreen、CefSharp.WinForms版本完全一致,无间接引用的旧版本包
  • 手动补充运行时文件
    重建后检查测试项目输出目录(如bin\Debug\x64)是否存在CefSharp.Core.Runtime.dll,若缺失,从NuGet包目录手动复制:

    • 从C:\Users\[你的用户名]\.nuget\packages\cefsharp.common\121.3.130\runtimes\win-[x64/x86]\native复制相关原生文件,从lib\net452复制CefSharp.Core.Runtime.dll到输出目录

内容的提问来源于stack exchange,提问作者Divya Muruganantham

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.28 20:02:08