I see two questions here. Correct me if I'm no providing enough information.
AssermblyResolve
event is invoked only if loader doesn't manage to find assembly it is looking for. So, first assembly load locations are probed, and then if assembly is not found,AssermblyResolve
event is invoked. If all assemblies are loaded correctly,AssemblyResolve
event will not fire at all.It is possible to load assembly manually to default
AppDomain
if that is what you mean. When assembly doesn't load correctly, andAssemblyResolve
of theAppDomain
fires, you have a chance to resolve it manually.
First you attach to the event to get informed that loading an assembly has failed
AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
And then try to load replacement assembly from a different place, depending on your criteria:
static System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
if (args.Name == "ClassLibrary1, Version=2.0.0.0, Culture=neutral, PublicKeyToken=e261024fcc198a53")
return Assembly.LoadFile("d:\\differentPath\\ClassLibrary1.dll");
else
return null;
}
Binding redirects as far as I know are useful for redirecting to a different version of assembly, but not redirecting loader to specific path where to look for assemblies.