We have a .net 4.6.2 project that is distributed as "Prefer 32-bit" on AnyCPU, and is using CefSharp whose package has both x86 and x64 versions.
Following the recommendation (Option 1) in the CefSharp project to add AnyCPU support I did the following:
- Added true to the first in my .csproj file
- Added the following to in my app.config file:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="x86"/>
</assemblyBinding>
</runtime>
- As already noted, all my project configurations are set to "Prefer 32-bit"
- Initialized Cef at startup with:
var settings = new CefSettings();
settings.BrowserSubprocessPath = @"x86\CefSharp.BrowserSubprocess.exe";
Cef.Initialize(settings, performDependencyCheck: false, browserProcessHandler: null);
All works fine in Debug, but when I try to build my Release version I get an error - with verbose mode:
2>SGEN : error : Could not load file or assembly 'CefSharp.Core.dll' or one of its dependencies. The specified module could not be found.
And further up I can see it is passing in the following references to SGEN:
2> References= 2>C:\SVN\MySolution\Branches\MyBranch\packages\CefSharp.Common.63.0.2\build..\CefSharp\x86\CefSharp.Core.dll 2>C:\SVN\MySolution\Branches\MyBranch\packages\CefSharp.Common.63.0.2\build..\CefSharp\x86\CefSharp.dll 2>C:\SVN\MySolution\Branches\MyBranch\packages\CefSharp.WinForms.63.0.2\build..\CefSharp\x86\CefSharp.WinForms.dll
Which appears to be from the CefSharp.Common.props file:
<ItemGroup>
<Reference Include="CefSharp">
<HintPath>$(MSBuildThisFileDirectory)..\CefSharp\x86\CefSharp.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="CefSharp.Core">
<HintPath>$(MSBuildThisFileDirectory)..\CefSharp\x86\CefSharp.Core.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
Or the CefSharp.Common.targets file:
<ItemGroup>
<CefSharpCommonBinaries32 Include="$(MSBuildThisFileDirectory)..\CefSharp\x86\*.*" />
...
</ItemGroup>
In case it was the "build.." part of the file names not getting resolved by SGEN, I tried hard-coding "$(MSBuildThisFileDirectory).." (lots of reasons I wouldn't want to actually do this for real; but it was a test) but got exactly the same issue, but with the correct absolute paths passed in as references to SGEN:
2> References= 2>C:\SVN\MySolution\Branches\MyBranch\packages\CefSharp.Common.63.0.2\CefSharp\x86\CefSharp.Core.dll 2>C:\SVN\MySolution\Branches\MyBranch\packages\CefSharp.Common.63.0.2\CefSharp\x86\CefSharp.dll 2>C:\SVN\MySolution\Branches\MyBranch\packages\CefSharp.WinForms.63.0.2\CefSharp\x86\CefSharp.WinForms.dll
Which leaves me with the problem of why SGEN cannot load the dlls. So, my current thinking is that this is due to a missing dependency. Should I be expecting the libcef.dll in this list of references? I have the other packages added to my .csproj file:
<Import Project="..\packages\cef.redist.x86.3.3239.1723\build\cef.redist.x86.props" Condition="Exists('..\packages\cef.redist.x86.3.3239.1723\build\cef.redist.x86.props')" />
<Import Project="..\packages\cef.redist.x64.3.3239.1723\build\cef.redist.x64.props" Condition="Exists('..\packages\cef.redist.x64.3.3239.1723\build\cef.redist.x64.props')" />
I've also tried commenting out the second/x64 import line above, to no avail.
[Update] I've just got turned on Fusion logging (as per Yavor Georgiev's blog post on SGEN errors) and according to that the dll loaded fine.