1

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:

  1. Added true to the first in my .csproj file
  2. Added the following to in my app.config file:
     <runtime>
         <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
             <probing privatePath="x86"/>
         </assemblyBinding>
     </runtime>
  1. As already noted, all my project configurations are set to "Prefer 32-bit"
  2. 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.

monty
  • 1,543
  • 14
  • 30
  • 1
    Know problem, if you do find a solution then please post on https://github.com/cefsharp/CefSharp/issues/2223 – amaitland Mar 22 '18 at 01:38

1 Answers1

3

I had a similar problem in a legacy VB.Net WinForm project I took over. After swapping out the old WebControl for CefSharp, we could build and run in Debug mode just fine, but a Release build would fail.

I noticed that the File listed on the build error was SGEN - the XmlSerializationGenerator.

As far as I could tell there were no objects that required XmlSerializtion, so I went to the Project Properties > Compile > Advanced Compile Options and changed "Generate serialization assemblies:" from Auto to No.

The solution builds and runs just fine in Release mode now.

Gary.Ray
  • 6,441
  • 1
  • 27
  • 42