cefSharp anycpu

 

You must add <CefSharpAnyCpuSupport>true</CefSharpAnyCpuSupport> to the first <PropertyGroup> in your project (e.g. .csproj file).

 AppDomain.CurrentDomain.AssemblyResolve += Resolver;

https://github.com/cefsharp/CefSharp/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aclosed+anycpu

 

Option 2
Add a dependency resolver, this is more complicated and needs to be hooked up before any calls to classes in the CefSharp.* namespaces. Here is one method of doing this, I'll add some helper classes in the future. It's important that LoadApp is not in-lined, so the calls to CefSharp are delayed long enough to hookup the Assembly Resolver

Add <CefSharpAnyCpuSupport>true</CefSharpAnyCpuSupport> to the first <PropertyGroup> in your project (e.g. .csproj file).
Implement the code below (modifying any setting that you require).
[STAThread]
public static void Main()
{
    AppDomain.CurrentDomain.AssemblyResolve += Resolver;

    LoadApp();
}

[MethodImpl(MethodImplOptions.NoInlining)]
private static void LoadApp()
{
    var settings = new CefSettings();

    // Set BrowserSubProcessPath based on app bitness at runtime
    settings.BrowserSubprocessPath = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase,
                                           Environment.Is64BitProcess ? "x64" : "x86",
                                           "CefSharp.BrowserSubprocess.exe");

    // Make sure you set performDependencyCheck false
    Cef.Initialize(settings, performDependencyCheck: false, browserProcessHandler: null);

    var browser = new BrowserForm();
    Application.Run(browser);
}

// 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"))
    {
        string assemblyName = args.Name.Split(new[] { ',' }, 2)[0] + ".dll";
        string archSpecificPath = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase,
                                               Environment.Is64BitProcess ? "x64" : "x86",
                                               assemblyName);

        return File.Exists(archSpecificPath)
                   ? Assembly.LoadFile(archSpecificPath)
                   : null;
    }

    return null;
}
 AppDomain.CurrentDomain.AssemblyResolve += Resolver;


 private Assembly Resolver(object sender, ResolveEventArgs args)
    {
      if (args.Name.StartsWith("CefSharp"))
      {
        string assemblyName = args.Name.Split(new[] { ',' }, 2)[0] + ".dll";
        string archSpecificPath = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase,
                                               Environment.Is64BitProcess ? "x64" : "x86",
                                               assemblyName);

        return File.Exists(archSpecificPath)
                   ? Assembly.LoadFile(archSpecificPath)
                   : null;
      }

      return null;
    }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章