I am trying to implement dynamic loading of certain assemblies based on Environment.Is64BitProcess
.
This basically works like this:
- Register an event handler for the
AppDomain.AssemblyResolve
event In the event handler load the assembly from the CPU type dependent sub path:
private Assembly OnAssemblyResolve(object sender, ResolveEventArgs args) { // args.Name is the display name of an assembly, e.g.: // MyAssembly, Version=5.0.0.0, Culture=neutral, PublicKeyToken=abcdefghijklmn if(!args.Name.Contains("MyAssembly")) return null; var path = Path.Combine(GetCpuTypeDependentPath(), "MyAssembly.dll"); return Assembly.LoadFrom(path); }
Now, this has the problem, that it doesn't check for the version, publicKeyToken etc of the loaded assembly.
What I would like to do now is to call Assembly.Load
and simply supply an additional probing path. I know that this doesn't work as there is no such overload. Is there some other way to achieve my goal?