0

I have a WPF DLL project that contains my custom controls, themes, styles, etc., that is built as AnyCPU.

I have a dependency on an open source web browser control that doesn't have native AnyCPU support, but does have separate x86/x64 assemblies.

In an EXE, it is fairly simple. I can handle the AppDomain.CurrentDomain.AssemblyResolve event check for a 64 bit process and do an Assembly.LoadFile with the proper assemblies.

How do I dynamically resolve the dependency at runtime in a DLL project?

Keithernet
  • 2,349
  • 1
  • 10
  • 16
  • My question is, do you even have to? Can you add your DLL project as a reference in your EXE project, and do the dynamic assembly resolve for the third party DLL, and it will just work? Have you tried? Any errors? – Zack Sep 12 '16 at 21:18
  • Or you may have to just build your DLL project as x86 and x64 and dynamically load it as well... I don't have much experience with dynamic resolution, so I may be way off, just trying to think of a solution. – Zack Sep 12 '16 at 21:20
  • Try http://stackoverflow.com/questions/108971/using-side-by-side-assemblies-to-load-the-x64-or-x32-version-of-a-dll/156024#156024 and http://stackoverflow.com/questions/2963809/anycpu-x86-x64-for-c-sharp-application-and-its-c-cli-dependency – neohope Sep 13 '16 at 02:33

1 Answers1

1

It turns out, I was overthinking the issue.

In my WPF DLL, I have a custom control class that is using the open source web browser control.

In the static constructor of the custom control, I setup a handler for the AppDomain.CurrentDomain.AssemblyResolve event.

And for my handler:

    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, "CefSharp", Environment.Is64BitProcess ? "x64" : "x86", assemblyName);
            return File.Exists(archSpecificPath) ? Assembly.LoadFile(archSpecificPath) : null;
        }

        return null;
    }

In the handler I check to see if a CefSharp assembly is being resolved, and if so, I create a path to the proper assembly based on if my assembly is running in a 64 bit process or not, and then do an Assembly.LoadFile().

I hope this is helpful!

Keithernet
  • 2,349
  • 1
  • 10
  • 16