CefSharp NuGet包,AnyCPU无法找到文件

时间:2017-10-09 13:51:03

标签: c# nuget cefsharp anycpu

我目前正在尝试编写一个小服务,它使用CefSharp(v57.0.0)将HTML呈现为PDF文件,并按照说明使用"任何CPU"在我的项目中(Feature Request - Add AnyCPU Support)。 在我的项目中,我使用了下面的程序集解析器似乎工作正常(它在初始化期间加载CefSharp.Core.dll,CefSharp.dll):

// 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;
    }

对于CefSharp的初始化,我设置了与示例中完全相同的值:

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);

但是,如果我开始我的简单测试,我会收到以下错误代码:

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

任何想法可能会发生在这里以及如何解决问题?

1 个答案:

答案 0 :(得分:1)

消息非常清楚,无法加载其他程序集。

以下是有关如何执行此操作的一些通用说明:

  • 首先使用LoadLibraryFreeLibrary
  • 加载原生的(例如libcef.dll)
  • 看看加载托管版本是否会自动加载其依赖的其他托管版本,否则处理它们(繁琐)

您可能对这些用于发现依赖关系的工具感兴趣: