2

Currently im working on new project using CefSharp.OffScreen.NETCore, but I've got issue running it in Rider. Project building successfully, but on run this exception appears:

System.BadImageFormatException: Could not load file or assembly 'CefSharp.Core.Runtime, Version=107.1.120.0, Culture=neutral, PublicKeyToken=40c4b6fc221f4138'. An attempt was made to load a program with an incorrect format.

Then I've tried to build and run it in Visual Studio and after rebuild it runs fine. This issue happens only with CefSharp package, other projects with absolutely different packages runs without any exceptions.

Running configuration is same in Visual Studio and Rider (Debug x64, but tried all available - nothing changes). As I think there is might be problem with Rider MSBuild configuration, it might pass wrong parameters to build project.

I've tried reinstall vc redist, clean project, run project with different configuration (x64, x86, AnyCPU, Prefer 32bit also tried), use "Pass VisualStudio parameters to build" parameter in Rider build settings, create new project with simple CefSharp usage, even run project in both IDEs on absolutely clean PC. Nothing of it didn't help. All packages CefSharp.OffScreen need are installed.

It will be nice to got an example what parameters Visual Studio use, so I can try pass them in Rider. enter image description here enter image description here enter image description here

vladuska
  • 41
  • 4
  • 1
    Related? https://stackoverflow.com/questions/51556943/build-x64-project-with-cefsharp – stuartd Jan 22 '23 at 00:29
  • @stuartd nope, nothing helpful in here. – vladuska Jan 22 '23 at 01:35
  • you sure, it usually is the problem , a mismatch between the bitness of a library and the main project – pm100 Jan 22 '23 at 01:56
  • What are your project settings? 64 Bit? Any CPU? – jdweng Jan 22 '23 at 02:02
  • @pm100 attached screenshots of configuration in VS and Rider, with that configuration VS is working fine, Rider is getting exception. – vladuska Jan 22 '23 at 02:26
  • @jdweng check screenshots please. – vladuska Jan 22 '23 at 02:26
  • At least the last screen shot should be changed to Markdown embedded code snippet. – Lex Li Jan 22 '23 at 03:13
  • Before exhausted by trying out a lot of IDE settings, you might try to go back to the very basic MSBuild bin log, https://msbuildlog.com/ Enable it in both VS and Rider, so that you can compare how exactly the binaries are generated by MSBuild. From there you might get some hints on where the bitness is wrongly chosen and the solution will reveal itself. – Lex Li Jan 22 '23 at 03:17
  • Try https://github.com/cefsharp/CefSharp/wiki/Quick-Start-For-MS-.Net-5.0-or-greater#20-set-a-runtimeidentifier-in-your-proj-file – amaitland Jan 22 '23 at 09:43
  • Remove the `chromiumembeddedframework` entries in your `PackageReference` itemgroup and run `dotnet publish YourSolution.sln -f net5.0-windows -r win-x64 --self-contained false --verbosity n` from the command line to see what you get. – amaitland Jan 22 '23 at 09:58
  • Look at message in first screen shot in the brown URL. Second screen shot indicates the Cefsharp.Core.Runtime version is wrong. It appears that VS attempted to update a project from an earlier version and failed which often leaves a project in a state where the compiler fails. The best way of solving a version issue is from Solution Explorer under references delete the failed reference and then add again so the version of the library matches the latest library installed on you system. Make backups just incase you can't find the library. Also make sure cefsharp version matches core version. – jdweng Jan 22 '23 at 11:06
  • Doing a clean build on projects also will help find issues. When you update library the compiler may not recompile intermediate obj files and these old obj files may be causing issues. Clean build will recompile everything. – jdweng Jan 22 '23 at 11:09

1 Answers1

1

You have added the nuget package chromiumembeddedframework.runtime.win-arm64 but I'm pretty sure you meant to add x64 :)

Sire
  • 4,086
  • 4
  • 39
  • 74
  • Thanks! But, that's not a fully correct answer. I noticed that PackageReference set to "Remove" for no reason. It works fine when changing "chromiumembeddedframework.runtime.win-x64" reference to include. Still can't understand why in that case VS works... – vladuska Jan 23 '23 at 23:10