Force load an assembly from the /bin and not the GAC?

Michael Stum picture Michael Stum · Jun 9, 2011 · Viewed 20k times · Source

I have two assemblies, created through conditional compilation (dev and real).

The public surface of these assemblies is 100% identical: both are strongly named; both are signed with the same .snk and therefore have the same PublicKeyToken; both have the same culture and the same version. I cannot change this: making them appear identical is the whole point.

However, on my machine the real assembly is in the GAC. I have an ASP.NET 3.5 WebForms app that references the dev assembly. It absolutely must do that; the real assembly crashes the app.

Is there a way to force a specific ASP.NET application to use the dev one (which is in /bin), given that:

  • There is one in the GAC.
  • Both have the same Version and PublicKeyToken.
  • Both are strongly named/signed with the same key.
  • I can not change them, can't change the version, and can't remove the key.

I noticed that someone already asked this in #991293, but the accepted answer involved removing the signing, which isn't an option here.

Am I out of luck?

Answer

JaredPar picture JaredPar · Jun 9, 2011

No there is no way to do this. When loading an assembly the CLR will check to see if a DLL with an equivalent strong name is present in the GAC. If there is a matching assembly in the GAC it will pick the GAC assembly every time. There is unfortunately no way to override this behavior.