64

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?

Aaron Anodide
  • 16,906
  • 15
  • 62
  • 121

1 Answers1

42

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."

jbl
  • 15,179
  • 3
  • 34
  • 101
  • thanks, that's the information I was hoping to get. do you feel like you understand this to the point that your answer is authoritative? (please don't take that the wrong way) – Aaron Anodide Feb 24 '13 at 21:19
  • 1
    @AaronAnodide : nope, I don't think my answer is authoritative. That's just the way I understand the documentation, and I have used it something like ... 3 times. Don't worry I don't take that the wrong ;-) – jbl Feb 24 '13 at 21:23
  • 4
    Yep, you guys are right, I used it for the sort of same purpose; for example say I have a library called libA.dll and another library called libB.dll. My version of libA.dll is compiled against version 1.0 of libB.dll. I have updated my application with a newer version of libB.dll (say 1.5) and libA.dll is no longer working. I would use this feature to instruct the runtime to get libA.dll to work with the newer version of libB.dll (the other, arguably better option is, if I have source code of libA.dll to compile it against the newer version of libB.dll). – Chintana Meegamarachchi Feb 25 '13 at 03:14
  • 2
    A killer feature and a life saver when you work with legacy codebases with long lost source code – Chintana Meegamarachchi Feb 25 '13 at 03:14