2

I am getting System.IO.FileNotFoundException: 'Could not load file or assembly 'CefSharp.Core.Runtime, Version=89.0.170.0, Culture=neutral, PublicKeyToken=40c4b6fc221f4138'. The system cannot find the file specified.' the file is there and in the bin directory along with the other DLLs.

Project set up:

Console app targeting netcore 3.1 consumes a class library targeting netstandard 2.0 which loads in a driver built using netcore app 3.1 which has CefSharp.Offscreen 89.0.170

When stepping through the debugger I am seeing that I cannot load the CefSharp.Core.Runtime.dll which CefSharp.Core depends on. An attempt was made to load a program with an incorrect format. (0x8007000B).

The dlls are taken from the x64 folder of the cef nuget package and reflect that in the csproj.

C:\Users\{user}\.nuget\packages\cefsharp.common.netcore\89.0.170\runtimes\win-x64\lib\netcoreapp3.1

I am at a loss as to what is causing this, has anyone got any suggestions on where to look and what could be the cause?

EDIT 1 -- code to clarify

private static System.Reflection.Assembly Resolver(object sender, ResolveEventArgs args)
{
    if (!args.Name.StartsWith("CefSharp.Core.Runtime")) return null;
    string assemblyName = args.Name.Split(new[] {','}, 2)[0] + ".dll";
    string archSpecificPath = $"E:\\myProject\\bin\\Debug\\netcoreapp3.1\\{assemblyName}";

    // this returns true
    var exists = File.Exists(archSpecificPath);
    try
    {
        return System.Reflection.Assembly.LoadFile(archSpecificPath);
    }
    catch(Exception e)
    {
        // e's value: "An attempt was made to load a program with an incorrect format. (0x8007000B)"
        return null;
    }

EDIT 2 - contents of bin and where they're from

packages\cefsharp.common.netcore\89.0.170\runtimes\win-x64\lib\netcoreapp3.1

CefSharp.Core.dll

CefSharp.dll

CefSharp.Core.Runtime.dll

packages\cefsharp.offscreen.netcore\89.0.170\lib\netcoreapp3.1

CefSharp.OffScreen.dll

EDIT 3 - updated bin

enter image description here

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
PurpleSmurph
  • 2,055
  • 3
  • 32
  • 52
  • 2
    Unfortunately BadImageFormatException when loading a VC++ dll under .Net Core 3.1 is rather misleading. It can in fact mean a number of things. Any attempt to load CefSharp.Core.Runtime.dll which fails for any reason results in BadImageFormatException. If CefSharp.Core.Runtime.dll is unable to load libcef.dll you will also get the same BadImageFormatException. Do you have libcef.dll and all of the other bin/pak/dll files listed at https://github.com/cefsharp/CefSharp/wiki/Output-files-description-table-%28Redistribution%29 in the same directory as CefSharp.Core.Runtime.dll? – amaitland May 06 '21 at 19:39
  • Thank you for your reply, I'm missing some which I can't find in the nuget folders I've got. I've added a picture of the current dlls I have in the bin. icudtk.dat, snapshotblob.bin, v8_context_snapshot.bin from the required section. Where can I find these? – PurpleSmurph May 06 '21 at 20:15
  • 2
    https://www.nuget.org/packages/cef.redist.x64/ contains all the CEF resources for x64. Are you manually copying files from the Nuget packages? – amaitland May 06 '21 at 20:23
  • Thanks! Yes I am, as the necessary files weren't put into the bin when building the application. – PurpleSmurph May 06 '21 at 20:24
  • 2
    The CefSharp.Offscreen package whilst running under .Net Core is actually .Net 4.5.2 dlls. A separate set of packages for .Net Core/.Net 5.0 are available. See https://github.com/cefsharp/CefSharp/issues/3284#issuecomment-772132523 version 89 is available in these packages also. No guarantee it resolves your problem, I'd need more details to know what's going on. – amaitland May 06 '21 at 20:49
  • Okay, thank you, will check that link out. One more question if I may: When building with `cef.redist.x64`, `CefSharp.Common.NETCore` and `CefSharp.OffScreen` as the nuget packages referenced, I get the error of `CefSharpOffScreen couldn't be found` even though it's there, the files in the list in the link you shared do not get moved to the same directory as `CefSharp.Core.Runtime` - should they? – PurpleSmurph May 06 '21 at 20:52
  • 1
    Firstly as you are using PackageReference you should only include the top level package, in this case CefSharp.OffScreen. If all your projects are in the same solution and you have a ProjectReference in your project file then the dependencies should be added to your consuming project. If you don't have a reference between projects then you'll need to manually copy the files. Look in your obj folder at the files that msbuild generates, they'll give you a better understanding of what references are included, I don't remember the exact file names off the top of my head. – amaitland May 06 '21 at 21:41
  • Did you fix it? – xavier Dec 22 '21 at 17:50

0 Answers0