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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31172045/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 13:14:32  来源:igfitidea点击:

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

c#wpfcefsharp

提问by CaptainBli

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.
This means the problem is due to the dlls not being correct bitness.

当我运行时,我得到: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.
这意味着问题是由于 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). There are also another copy of dlls that point to an empty path in the properties panel. The problem is that the x64 version crashes with a bad image error because it is referencing the x86 versions of the dlls.

在版本 41.0.0 中,nuget 包添加了指向正确路径(x86 文件夹)的 x86 版本的 dll 引用。还有另一个 dll 副本指向属性面板中的空路径。问题是 x64 版本因错误图像错误而崩溃,因为它引用了 x86 版本的 dll。

I have back tracked to 39.0.2 and CefSharp works for me. I have both sets of dlls and where x86 and x64 versions of my application compile and run as expected.

我已经回溯到 39.0.2 并且 CefSharp 对我有用。我有两组 dll,其中 x86 和 x64 版本的应用程序按预期编译和运行。

When I upgrade again to 41.0.0 same problem as before. The x64 version will compile though the application uses x86 versions of the dll which crashes when trying to display the first browser. 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. (At least I believe this is the case a

当我再次升级到 41.0.0 和以前一样的问题。尽管应用程序使用 x86 版本的 dll,但在尝试显示第一个浏览器时会崩溃,但 x64 版本将编译。我尝试重建所有并删除自动复制的 dll,并且在编译期间再次复制 x86 版本。(至少我相信是这种情况

Two Sets of Dlls

两套dll

I then removed all of the dlls in the references and manually added the x64 versions. The compilation and execution worked correctly as it did with the 39.02 version of CefSharp.WPF.

然后我删除了引用中的所有 dll 并手动添加了 x64 版本。编译和执行与 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. Now x64 works and x86 doesn't. The paths of the dlls are now x64 folders.

另一个注意事项:我可以在设置为 x64 时使用 nuget,这与上述问题相反。现在 x64 可以工作,而 x86 不行。dll 的路径现在是 x64 文件夹。

采纳答案by CaptainBli

It turns out, after much tribulation and anguish, I found that the References were not setup correctly in my .csproj. They were defined as being x64 somehow.

事实证明,在经历了很多磨难和痛苦之后,我发现在我的.csproj. 它们以某种方式被定义为 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. Note that the actual references are defined by the Importat the top of the project.

我一注释掉HintPath,它就开始正常工作。请注意,实际引用由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 .propsfiles setup the actual HintPaththat is necessary for it to copy the correct .dllsover to the build folder. I am uncertain as to how my project ended up with the path set incorrectly.

这些.props文件设置了HintPath将正确内容复制.dlls到构建文件夹所需的实际内容。我不确定我的项目是如何以错误的路径设置结束的。