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

时间:2015-07-01 21:30:59

标签: c# wpf cefsharp

当我跑步时,我得到: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的位数不正确。

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

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

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

Two Sets of Dlls

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

如何在不必手动更改dll路径的情况下使两个版本都能正常工作?

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

2 个答案:

答案 0 :(得分:2)

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>

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

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.

答案 1 :(得分:1)

使用 Visual Studio 2017,winforms 应用程序,我在一台机器上升级 Nuget 包后遇到错误,上传到 Github,然后在另一台机器上,我执行了一个 git a Pull 来更新我的解决方案文件。导致在第二台机器上出现上述错误。

补救措施: 删除 /bin 和 /obj 中的文件夹。 重建解决方案。