How can I force .NET to use a local copy of an assembly that's in the GAC

Solution 1:

Make sure the GAC Assembly and local Assembly have different version numbers (not a bad idea to let your build number, at least, auto-increment by wild-carding your AssemblyVersion in AssemblyInfo: [assembly: AssemblyVersion("1.0.0.*")] ). Then, redirect your assembly binding using your app's config:

  • http://msdn.microsoft.com/en-us/library/2fc472t2(VS.80).aspx
  • http://msdn.microsoft.com/en-us/library/433ysdt1(VS.80).aspx.

In your case, you won't need the "appliesTo" attribute of the assemblyBinding config. You just need something like:

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
            <assemblyIdentity name="YourAssembly" publicKeyToken="AAAAAAAAAAAA" culture="neutral"/>
            <bindingRedirect oldVersion="0.0.0.0-5.2.1.0" newVersion="5.0.8.1"/>
        </dependentAssembly>
    </assemblyBinding>
</runtime>

Solution 2:

If they have the same version number the answer is you can't. If you attempt to load an assembly that has the same full assembly name (name, version, key) as a GAC'd assembly the CLR will pick the GAC'd assembly every single time.

Solution 3:

You can set the DEVPATH to force load an assembly, see link text

This doesn't answer your question since it only meant for development use and even then not really recommended as it doesn't mirror production usage. However I thought I'll share it anyway since it's good to know.