.netreflectionassembliesappdomainassembly-loading

LoadFrom and context


I am loading through Assembly.LoadFrom an assembly (A) which is stored outside of the application base path; the assembly I load references another .net assembly (B) in the same directory.

When I try to use some methods of the A assembly, Fusion logs reveal that the system is trying to load B.dll from the application base directory rather than the parent directory of A.dll.

I added a listener to AppDomain.CurrentDomain.AssemblyResolve, which is invoked with the sender AppDomain having a message saying "There are no context policies.", and the ResolveEventArgs.RequestingAssembly property set to null.

Shouldn't LoadFrom allow searching for an assembly's dependencies in its parent directory?


Solution

  • Yes, I think it should but leppie is correct, it doesn't. Here is a detailed MSDN article about the assembly probing sequence. There have been several times where I had the exact same issue and using the AssemblyResolve event is the only way.