无法同时为x64和x86加载文件或程序集'CefSharp.Wpf;只有一件作品 [英] Could not load file or assembly 'CefSharp.Wpf for both x64 and x86; only one works

查看:350
本文介绍了无法同时为x64和x86加载文件或程序集'CefSharp.Wpf;只有一件作品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行时,我得到:无法加载文件或程序集 CefSharp.Wpf,版本= 41.0.0.0,区域性=中性,公共密钥令牌= 40c4b6fc221f4138或其依赖项之一。试图加载格式错误的程序。

这意味着问题是由于dll的位数不正确。

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.

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

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.

我已经追溯到39.0.2,CefSharp可以正常工作为了我。我拥有这两组dll,并且我的应用程序的x86和x64版本可以在其中编译并按预期运行。

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.

当我再次升级到41.0.0时,与以前相同的问题。尽管该应用程序使用DL​​L的x86版本,但x64版本仍会编译,该dll在尝试显示第一个浏览器时会崩溃。我试图重新构建所有文件,并删除自动复制到其中的dll,并且在编译过程中再次复制了x86版本。 (至少我相信是这样的情况

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

然后我删除了引用中的所有dll,并手动添加了x64版本,编译和执行与39.02版本一样正确

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路径的情况下使两个版本都能正常工作?

How can I get both versions to work without having to manually change the dll paths?

另一注:我可以在设置为x64的情况下使用nuget,这与上述问题相反。现在x64可以正常工作,而x86却不能。DLL的路径现在是x64文件夹。

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.

推荐答案

事实证明,经过许多苦难和痛苦之后,我发现我的 .csproj

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.

<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>

我注释掉 HintPath ,它开始正常工作。请注意,实际引用是由项目顶部的 Import 定义的。

As soon as I commented out the HintPath, it started working correctly. Note that the actual references are defined by the Import at the top of the project.

<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')" />

这些 .props 文件设置实际的 HintPath ,它是将正确的 .dlls 复制到构建文件夹所必需的。我不确定我的项目最终如何设置错误的路径。

These .props files setup the actual HintPath that is necessary for it to copy the correct .dlls over to the build folder. I am uncertain as to how my project ended up with the path set incorrectly.

这篇关于无法同时为x64和x86加载文件或程序集'CefSharp.Wpf;只有一件作品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆