How to load a referenced DLL from a specified location, not a GAC?

I have a dll named A.dll with a strong name, another assembly B references A.dll. I put A.dll in c: \ myapp, and also A.dll is installed in the GAC. I hope assembly B loads A.dll from c: \ myapp not GAC. But it always loads A.dll from the GAC. My question is how to load the reference DLL from the specified local location, not the GAC. Thanks.

+4
source share
4 answers

According to the MSDN page on how the CLR loads assemblies , the CLR will load assemblies from the GAC before trying to load assemblies from the working directory. It seems that this is not so.

Alternatively, you simply cannot add the assembly to the GAC so that the CLR is forced to find the assembly study .

+3
source

You will have to give it another [AssemblyVersion]. Which ultimately makes sense if the version numbers are the same, then there is no reason why the GAC version will not be good.

+2
source

The only way is to use Assembly.LoadFile () to load the assembly. This allows you to specify the download path.

There are a few mistakes that make this very painful:

  • You must execute Assembly.LoadFile () before loading the assembly automatically
  • None of the A.dll dependencies load automatically; you have to download all of them manually
  • A.dll will not load in the LoadFrom context (see msdn for more information), which actually means any code referenced by A.dll cannot just use types from A.dll, you should use reflection
0
source

This can be done by deploying the CLR and implementing IHostAssemblyManager and IHostAssemblyStore. It looks like using a bazooka to kill a mosquito, though.

0
source

All Articles