LoadFrom and context

3.1k views Asked by At

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?

2

There are 2 answers

0
EverPresent On BEST ANSWER

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.

0
Eugene Strizhok On

Well, actually it should! And it does. See:

An while CLR still tries to resolve dependencies of assembly (A) using GAC and appbase directory, it will also look in the folder (A) was loaded from.