What is the purpose of bindingRedirect tag in web.config file of .NET?

The tag bindingRedirect has its significance when multiple versions of an assembly persist in GAC and you have to choose which version to actively use. Assume that your application is using a DLL which is put up in GAC.



At a later point of time, another version of the same DLL is created and put up in GAC. Now when you are running your application, which version of DLL will it refer? The version of DLL which is used during compilation of your application will be referred while executing the application. This is the default behavior.

However, .NET gives you a provision to choose whichever version of DLL you want to refer while executing your application. This customized behavior can be achieved in .NET by specifying the bindingRedirect tag in web.config file. This tag has two attributes namely new version and old version. Whichever version is specified in the new version attribute will be binded to your application at run time. Here is a snippet from web.config file to give you an example of this tag:
<?xml version="1.0" encoding="utf?8" ?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name=" sampleAssembly"
publicKeyToken="87ba9ab67f9d45b2"
culture="neutral" />

<bindingRedirect oldVersion="2.0.0.1"
newVersion="1.0.1.1"/>

</dependentAssembly>
<publisherPolicy apply="no">
</assemblyBinding>
</runtime>
</configuration>

In this snippet of web.config file, you have configured runtime configuration settings for an assembly named sampleAssembly. This assembly has two versions namely 1.0.1.1 and 2.0.0.1. From the version numbering, it is clear that 1.0.1.1 is the older version and 2.0.0.1 is the latest version. But you want 1.0.1.1 to be binded to the application and not the latest version. To achieve this, you introduce the bindingRedirect tag and specify the oldVersion attribute value to be the actual latest version namely 2.0.0.1 and specify the newVersion attribute value to 1.0.1.1 which is the first version of the assembly that is created.

At run time, CLR will look at the configuration settings and fetch the newVersion value of bindingRedirect tag and use 1.0.1.1 as the version to be refered in GAC while executing the application.

| How do you prevent a class from overriding in .NET? | How are classes related to objects in .NET Application | How are Delegates different from Events in .NET? | How are system exceptions different from application exceptions in .NET? | How are Value Types different from Reference Types in .NET? | How can a finalize method be suppressed in .NET? | How can you call Stored Procedure in ADO.NET? | How can you force Dispose method to be called automatically in .NET? | How do you call a Base Class Constructor from Derived Class Constructor in .NET? | How do you connect your VB.NET application to SQL Server? | How do you implement Cloning in .NET? | How do you implement Façade Design Pattern in .NET? | How do you implement MVC Pattern in ASP.NET? | How do you install .NET Assembly in GAC? | How is shadowing different from overriding in .NET? | How to prevent a particular .NET DLL from being decompiled? | Illustrate Delay Signing Process of an Assembly in .NET? | What are Reference Types in .NET? | What are the advantages of C#? | What are the advantages of VB.NET? | What are the differences between Namespace and Assembly in .NET? | What are the similar features between class and structure in .NET? | What are Value Types in .NET? | What do you mean by mixed mode authentication in .NET? | What do you mean by Satellite Assembly in .NET? | What do you mean by shadowing in .NET? | What is CTS in .NET? | What is ILDASM in .NET? | What is Managed Code in .NET? | What is Manifest in .NET? | What is MSIL in .NET Framework? | What is the importance of finalize method in .NET? | What is the need for Visitor Pattern in C#? | What is the purpose of bindingRedirect tag in web.config file of .NET? | What is the purpose of CodeDom in .NET? | What is the purpose of dispose method in .NET? | What is the purpose of Ngen.exe in .NET? | What is the purpose of Strong Name in COM Components of .NET? | What is the purpose of virtual keyword in .NET? | What Object Oriented Principles can be incorporated in .NET Application? |


“Amazon and the Amazon logo are trademarks of Amazon.com, Inc. or its affiliates.”

| Privacy Policy for www.dotnet-guide.com | Disclosure | Contact |

Copyright - © 2004 - 2024 - All Rights Reserved.