0

I am currently trying to write a small service, which uses CefSharp (v57.0.0) to render HTML to a PDF file and followed the instructions to use "Any CPU" in my project (Feature Request - Add AnyCPU Support). In my project I used the following assembly resolver that seems to work fine (it loads CefSharp.Core.dll, CefSharp.dll during initialisation):

// Will attempt to load missing assembly from either x86 or x64 subdir
    private static Assembly Resolver(object sender, ResolveEventArgs args)
    {
        if (args.Name.StartsWith("CefSharp", StringComparison.Ordinal))
        {
            string assemblyName = args.Name.Split(new[] { ',' }, 2)[0] + ".dll";
            string archSpecificPath = Path.Combine(
                AppDomain.CurrentDomain.SetupInformation.ApplicationBase,
                Environment.Is64BitProcess ? "x64" : "x86",
                assemblyName);

            var outputAssembly = File.Exists(archSpecificPath) ? Assembly.LoadFile(archSpecificPath) : null;

            return outputAssembly;
        }

        return null;
    }

For the initialisation of CefSharp I set exactly the same values like in the example:

var settings = new CefSettings()
        {
            // By default CefSharp will use an in-memory cache, you need to specify a Cache Folder to persist data
            CachePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "CefSharp\\Cache")
        };

        // Perform dependency check to make sure all relevant resources are in our output directory.
        Cef.Initialize(settings, performDependencyCheck: true, browserProcessHandler: null);

However, if I start my simple test, I get the following error code:

Message: System.Exception : Unable to locate required Cef/CefSharp dependencies:
Missing:CefSharp.BrowserSubprocess.exe
Missing:CefSharp.BrowserSubprocess.Core.dll
Missing:CefSharp.Core.dll
Missing:CefSharp.dll
Missing:icudtl.dat
Missing:libcef.dll
Executing Assembly Path:D:\projects\CefService\bin\Debug\x86

Any ideas what might be happening here and how to solve the problem?

Octoate
  • 459
  • 1
  • 6
  • 18
  • Small update: I have changed my project to use "x86" or "x64" targets now (like the description linked above), which works if I call the conversion method from the main program. However, if I call it from NUnit, the program will crash. – Octoate Oct 10 '17 at 12:27
  • Another update: After playing around with CefSharp for two days, we decided to skip it and use a commercial tool. It worked out of the box and I was ablte to implement the required features in less than an hour. – Octoate Oct 19 '17 at 05:59

1 Answers1

1

The message is pretty clear, other assemblies could not be loaded.

Here are some generic instructions on how to do that:

  • load native ones (e.g. libcef.dll) first with LoadLibrary and FreeLibrary
  • see if loading a managed one will automatically load other managed ones it depends, else handle them (tedious)

You might be interested in these tools for spotting dependencies:

aybe
  • 15,516
  • 9
  • 57
  • 105
  • Thanks for your answer. Unfortunately this does not help me with my problem, because I set up the project in the way to support "Any CPU" and it should load those dependencies without any further actions. However, I was unable to create the "Minimal Example" from the CefSharp examples with "Any CPU" support. – Octoate Oct 10 '17 at 12:25
  • 1
    What I've laid out was how to make an managed AnyCPU load native dependencies made of 32 and 64-bit binaries, on the other hand if CefSharp has a working 'way' I'd rather try to get it to work. – aybe Oct 10 '17 at 23:26
  • That's what I am trying. However, I am currently also facing a problem with a callback method of the PrintToPdfAsync method (Task.Wait() will result in an stuck application) that I want to use. I debugged into it and can see that the result will not get fired. So I am currently not sure if I should still work on this solution or search for an alternative. – Octoate Oct 12 '17 at 08:05
  • Fix problems one by one and you should ask another question for an another problem. – aybe Oct 12 '17 at 14:44