When trying to access assemblies from a C# assembly, there are several methods:
Implement a
AssemblyResolve
event handler http://msdn.microsoft.com/en-us/library/system.appdomain.assemblyresolve(v=vs.110).aspxUse the property in the .config file to redirect assembly requests
As stated in http://msdn.microsoft.com/en-us/library/system.resolveeventargs.name(v=vs.110).aspx for the property of ResolveEventArgs of the event in (1): "Name is the assembly name before policy is applied."
However, I couldn't find any documentation about the order of these methods.
Is the AssemblyResolve
event handler called before the redirects are probed? Or the other way around?
Second, is there a possibility to somehow apply the policy to the ResolveEventArgs
? For example to request the redirected version range from the .config file?
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
And then try to load replacement assembly from a different place, depending on your criteria:
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.