Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 413
Aaron Anodide Avatar asked Feb 24 '13 20:02

Aaron Anodide


People also ask

What is Assemblybinding?

<dependentAssembly> <assemblyIdentity name="FooBar" publicKeyToken="32ab4ba45e0a69a1" culture="en-us" /> <bindingRedirect oldVersion="7.0.0.0" newVersion="8.0.0.0" /> </dependentAssembly>

What is bindingRedirect in web config?

Specify assembly binding in configuration files. You use the same XML format to specify binding redirects whether it's in the app configuration file, the machine configuration file, or the publisher policy file. To redirect one assembly version to another, use the <bindingRedirect> element.

What is auto generate binding redirects?

Binding redirects are added if your app or its components reference more than one version of the same assembly, even if you manually specify binding redirects in the configuration file for your app. The automatic binding redirection feature affects desktop apps that target . NET Framework 4.5. 1 or a later version.


1 Answers

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

like image 96
jbl Avatar answered Oct 13 '22 17:10

jbl