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

2

6

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.

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.

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.

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

Two Sets of Dlls

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.

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

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.

Ovariotomy answered 1/7, 2015 at 21:30 Comment(5)
Is the problem reproducible with the github.com/cefsharp/CefSharp.MinimalExample project? No changes were made to the Nuget package structure between 39.0.2 and 41.0.0, it's really a very minor upgrade in CefSharp terms (obviously a major upgrade to a new CEF version).Gamali
I will see if it happens with that project. Though I may not get to it till Monday.Ovariotomy
If I manually copy the files over after the compilation has been completed the build will execute and run correctly. It appears as though the build is copying the wrong version of files (x86 version is always getting copied). Where might I look to find this?Ovariotomy
The copy is performed by a msbuild target github.com/cefsharp/CefSharp.MinimalExample/blob/master/…Gamali
You pointed me to the project files that helped to find the problem with the references. Thank you @amaitland.Ovariotomy
O
4

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.

Ovariotomy answered 13/7, 2015 at 21:5 Comment(1)
There was a problem with relatively old versions that meant nuget didn't bring in the right references (esp when the 'bitness' solution wasn't selected first).Weeden
B
1

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. Resulted in above error on 2nd machine.

Remedy: Delete folders in /bin and /obj. rebuild solution.

Benedict answered 21/1, 2021 at 23:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.