views:

361

answers:

4

It is my understanding that .NET runtime will always look for referenced assemblies in GAC first and then in the local folders. Is there a setting in Web.Config that would invert this order?

+8  A: 

No. It's not possible to achieve this. If a DLL of equal version to the one referenced in your program exists in the GAC the CLR will always choose this one. There is no way to override this behavior.

JaredPar
Is it something to do with security?
codeulike
@codeulike, i believe it has more to do with servicing. I know less about the why and more about the ability to do so because I spent a lot of time trying to subvert this behavior before realizing it simply wasn't possible.
JaredPar
This is why the GAC is evil, in my book.
Benjol
+1  A: 

I'm not sure if there's something that will actually reverse the search order as such, but depending on your requirements you might want to look into assembly binding redirection which gives you quite a lot of control over which versions of assemblies are loaded.

Steve Willcock
This will change what version you bind. However the version you end up choosing will still be subject to the GAC rules I mentioned.
JaredPar
Indeed, clarified the answer a little to reflect this
Steve Willcock
A: 

More info. on work arounds in this SO thread.

JP Alioto
A: 

JaredPar is right - the GAC will always get polled first for the assembly. However, if you're like me, and want to have the DLL live in the GAC and still debug, you can add a build script to dump your .pdb file the same folder as the assembly in the GAC (it'll be in C:\windows\assembly\gac_msil\assembly.name_[public key token]).

Adam McKee