简体   繁体   English

无法为 x64 和 x86 加载文件或程序集 'CefSharp.Wpf; 只有一个作品

[英]Could not load file or assembly 'CefSharp.Wpf for both x64 and x86; only one works

When I run I get: Could not load file or assembly 'CefSharp.Wpf, Version=41.0.0.0, Culture=neutral, PublicKeyToken=40c4b6fc221f4138' or one of its dependencies. An attempt was made to load a program with an incorrect format.当我运行时,我得到: Could not load file or assembly 'CefSharp.Wpf, Version=41.0.0.0, Culture=neutral, PublicKeyToken=40c4b6fc221f4138' or one of its dependencies. An attempt was made to load a program with an incorrect format. Could not load file or assembly 'CefSharp.Wpf, Version=41.0.0.0, Culture=neutral, PublicKeyToken=40c4b6fc221f4138' or one of its dependencies. An attempt was made to load a program with an incorrect format.
This means the problem is due to the dlls not being correct bitness.这意味着问题是由于 dll 的位数不正确。

In version 41.0.0, the nuget package adds dll references to the x86 version which point to the correct path (an x86 folder).在版本 41.0.0 中,nuget 包添加了指向正确路径(x86 文件夹)的 x86 版本的 dll 引用。 There are also another copy of dlls that point to an empty path in the properties panel.还有另一个 dll 副本指向属性面板中的空路径。 The problem is that the x64 version crashes with a bad image error because it is referencing the x86 versions of the dlls.问题是 x64 版本因错误图像错误而崩溃,因为它引用了 x86 版本的 dll。

I have back tracked to 39.0.2 and CefSharp works for me.我已经回溯到 39.0.2 并且 CefSharp 对我有用。 I have both sets of dlls and where x86 and x64 versions of my application compile and run as expected.我有两组 dll,其中 x86 和 x64 版本的应用程序按预期编译和运行。

When I upgrade again to 41.0.0 same problem as before.当我再次升级到 41.0.0 和以前一样的问题。 The x64 version will compile though the application uses x86 versions of the dll which crashes when trying to display the first browser.尽管应用程序使用 x86 版本的 dll,但在尝试显示第一个浏览器时会崩溃,但 x64 版本将编译。 I tried to rebuild all as well as removing the dlls that are copied in automatically and during the compilation the x86 versions are copied in again.我尝试重建所有并删除自动复制的 dll,并且在编译期间再次复制 x86 版本。 (At least I believe this is the case a (至少我相信是这种情况

两套dll

I then removed all of the dlls in the references and manually added the x64 versions.然后我删除了引用中的所有 dll 并手动添加了 x64 版本。 The compilation and execution worked correctly as it did with the 39.02 version of CefSharp.WPF.编译和执行与 39.02 版本的 CefSharp.WPF 一样正常工作。

How can I get both versions to work without having to manually change the dll paths?如何在无需手动更改 dll 路径的情况下让两个版本都能正常工作?

Another note: I can use nuget while set to x64 and this makes the opposite of the above problem.另一个注意事项:我可以在设置为 x64 时使用 nuget,这与上述问题相反。 Now x64 works and x86 doesn't.现在 x64 可以工作,而 x86 不行。 The paths of the dlls are now x64 folders. dll 的路径现在是 x64 文件夹。

It turns out, after much tribulation and anguish, I found that the References were not setup correctly in my .csproj .事实证明,在经历了很多磨难和痛苦之后,我发现我的.csproj中的 References 没有正确设置。 They were defined as being x64 somehow.它们以某种方式被定义为 x64。

<Reference Include="CefSharp, Version=41.0.0.0, Culture=neutral, PublicKeyToken=40c4b6fc221f4138, processorArchitecture=AMD64">
  <SpecificVersion>False</SpecificVersion>
  <!--<HintPath>..\packages\CefSharp.Common.41.0.0\CefSharp\x64\CefSharp.dll</HintPath>-->
</Reference>
<Reference Include="CefSharp.Core, Version=41.0.0.0, Culture=neutral, PublicKeyToken=40c4b6fc221f4138, processorArchitecture=AMD64">
  <SpecificVersion>False</SpecificVersion>
  <!--<HintPath>..\packages\CefSharp.Common.41.0.0\CefSharp\x64\CefSharp.Core.dll</HintPath>-->
</Reference>
<Reference Include="CefSharp.Wpf, Version=41.0.0.0, Culture=neutral, PublicKeyToken=40c4b6fc221f4138, processorArchitecture=x86">
  <SpecificVersion>False</SpecificVersion>
  <!--<HintPath>..\packages\CefSharp.Wpf.41.0.0\CefSharp\x64\CefSharp.Wpf.dll</HintPath>-->
</Reference>

As soon as I commented out the HintPath , it started working correctly.一旦我注释掉HintPath ,它就开始正常工作。 Note that the actual references are defined by the Import at the top of the project.请注意,实际引用由项目顶部的Import定义。

<Import Project="..\packages\CefSharp.Wpf.41.0.0\build\CefSharp.Wpf.props" Condition="Exists('..\packages\CefSharp.Wpf.41.0.0\build\CefSharp.Wpf.props')" />
<Import Project="..\packages\CefSharp.Common.41.0.0\build\CefSharp.Common.props" Condition="Exists('..\packages\CefSharp.Common.41.0.0\build\CefSharp.Common.props')" />

These .props files setup the actual HintPath that is necessary for it to copy the correct .dlls over to the build folder.这些.props文件设置了将正确的.dlls复制到构建文件夹所需的实际HintPath I am uncertain as to how my project ended up with the path set incorrectly.我不确定我的项目是如何以错误设置的路径结束的。

Using Visual studio 2017, winforms application, I encountered the error after upgarding the Nuget package on one machine, uploading to Github, then on another machine, I executed a git a Pull to update my solution file there.使用 Visual Studio 2017,winforms 应用程序,我在一台机器上升级 Nuget 包后遇到错误,上传到 Github,然后在另一台机器上,我执行了一个 git a Pull 来更新我的解决方案文件。 Resulted in above error on 2nd machine.导致在第二台机器上出现上述错误。

Remedy: Delete folders in /bin and /obj.解决方法:删除/bin 和/obj 中的文件夹。 rebuild solution.重建解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM