.net - Dynamically Resolve Dependency at Runtime in C# DLL -


i have wpf dll project contains custom controls, themes, styles, etc., built anycpu.

i have dependency on open source web browser control doesn't have native anycpu support, have separate x86/x64 assemblies.

in exe, simple. can handle appdomain.currentdomain.assemblyresolve event check 64 bit process , assembly.loadfile proper assemblies.

how dynamically resolve dependency @ runtime in dll project?

it turns out, overthinking issue.

in wpf dll, have custom control class using open source web browser control.

in static constructor of custom control, setup handler appdomain.currentdomain.assemblyresolve event.

and 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 handler check see if cefsharp assembly being resolved, , if so, create path proper assembly based on if assembly running in 64 bit process or not, , assembly.loadfile().

i hope helpful!


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -