Dll in both the bin and the gac, which one gets used?

asp.netDeploymentGacBin

asp.net Problem Overview


We have a web application that's deployed to many websites with only frontend changes, the shared backend portion has it's DLL in the GAC so we only have to update that one dll and all the sites get the update.

Is there a way to override the GAC with a DLL in the /bin folder to test out new features before they get released?

asp.net Solutions


Solution 1 - asp.net

If it has the same version number as the referenced DLL, the GAC gets used.

If you increment the version number, rebuild the website referencing the new version number, put the new version in the /bin directory, then that DLL will be used.

If you do not want to change the version number, you're pretty much out of luck.

When .NET loads strong named assemblies, first it tries to decide what version number to use. It does this via the reference first, then it looks for publisher policies, then it looks for binding redirects in the configuration file.

After it does this, it looks for the assembly in the GAC, then in any codebase specified, then it probes various file system folders for the DLL. If at any one of those steps it finds the right version assembly, it stops.

If you are not changing the version number of your strong named assembly, .NET will find the original one in the GAC and stop looking. Note that because it stops when it finds one, and because looking in the GAC is first, specifying a codebase for your assembly will do no good unless you also specify a new version number.

Solution 2 - asp.net

I have been able to override the GAC with the assembly in the \bin folder using the <codebase>Element.

By specifying <codebase version="1.2.3.4" href="/bin/MyAssembly.dll" /> in my web.config file I can tell my application to use this version rather than the version specified in the GAC.

You may also want to take a look at the <probing>Element for specifying assembly locations?

Solution 3 - asp.net

I think I might be saying the same think as Adam Sills, but re-worded it for my understanding. Through my own testing, looks like this is what happens:

  • If your app is compiled with version 1.0.0.0 and 1.0.0.1 is in the GAC, then you can omit the .dll from your /bin.
  • If your app is compiled with version 1.0.0.1 and 1.0.0.0 is in the GAC, then you MUST place the .dll in your /bin to ignore the GAC. A error will occur if the GAC version is older than the required version of your app, unless you include the newer version in your /bin.

I hope this is correct...

Solution 4 - asp.net

You can view binding information in the log file using the Assembly Binding Log Viewer (Fuslogvw.exe), which is included in the Windows Software Development Kit (SDK).

s

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJohn BokerView Question on Stackoverflow
Solution 1 - asp.netAdam SillsView Answer on Stackoverflow
Solution 2 - asp.netIsolatedStorageView Answer on Stackoverflow
Solution 3 - asp.netJ.HendrixView Answer on Stackoverflow
Solution 4 - asp.netBALKANGraphView Answer on Stackoverflow