.net – GAC Assembly version to use based on Web.Config

.net, asp.net, gac

Good Day

I have a project that makes use of custom assemblies in the GAC:
To be able to use that, I added a Reference to my project in


(CopyLocal=False; SpecificVersion=False)
Also, i added this in the Web.Config file

<compilation debug="false" strict="true" explicit="true" targetFramework="4.0" >  <assemblies>    <add assembly="JOHN.CommonLib, Version=, Culture=neutral, PublicKeyToken=9cd884563ebafb62"/>          </assemblies ></compilation >

It's running as expected. The problem is when i install a new version
I install a new version to the GAC, and change the Web.Config accordingly

<add assembly="JOHN.CommonLib, Version=, Culture=neutral, PublicKeyToken=9cd884563ebafb62"/>

JOHN.CommonLib is a tester Class Library that returns either "1.0" or "2.0" depending on the version.

Issue: If I compile using 1.0, the webapps that make use of it always shows "1.0" even if i change the Web.Config between 1.0 and 2.0
I would like my web app to use the version that i write in my Web.Config

Any ideas?
I also stop and start the AppPool in between changing the Web.Config.

Best Solution

For strong named assemblies - application will always bind (if possible) to the version that it has been built with. To override this binding, you need to specify binding redirection for the assembly. There are multiple ways to do that - see this link. So one of the way to use app/web config file - for example,

<configuration>  <runtime>    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">      <dependentAssembly>        <assemblyIdentity name="JOHN.CommonLib"          publicKeyToken="9cd884563ebafb62"          culture="en-us" />        <!-- Assembly versions can be redirected in application,           publisher policy, or machine configuration files. -->        <bindingRedirect oldVersion="" newVersion="" />      </dependentAssembly>    </assemblyBinding>  </runtime></configuration>