What is the meaning/reason for the generated entries in web.config>configuration>runtime>assemblyBinding?

Aaron Anodide picture Aaron Anodide · Feb 24, 2013 · Viewed 21.4k times · Source

I've noticed this section in my web.config files for a while and I'm now trying to reason out what exactly the purpose is:

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

So, the first entry seems to say:

System.Web.Helpers is the name of a dependent assembly with a public key token of 31bf3856ad364e35. Redirect version 1.0.0.0 through 2.0.0.0 to version 2.0.0.0.

My best guess is that it means any code executing in the context of the ASP.NET run time that depends on an assembly with the specified name which also has a version in the specified range executes as if it were compiled with the specified version with the specified public key.

Does this mean if I have a web project that depends on a class library and that class library has a reference to an older version of the assembly which has a a bindingRedirect, that the code will execute as if it were compiled against the newer version?

Answer

jbl picture jbl · Feb 24, 2013

Does this mean if I have a web project that depends on a class library and that class library has a reference to an older version of the assembly which has a a bindingRedirect, that the code will execute as if it were compiled against the newer version?

You have it right (I would just say "...the code will execute as if it were referencing the newer version"), see http://msdn.microsoft.com/en-us/library/7wd6ex19%28v=vs.110%29.aspx

"When you build a .NET Framework application against a specific version of a strong-named assembly, the application uses that version of the assembly at run time. However, sometimes you might want the application to run against a newer version of an assembly."