Keyvan Nayyeri

Musings of a Ph.D. student in Computer Science

Redirect Assembly Versions Using bindingRedirect Element

Sometimes it's mandatory to use a specific version of an assembly when various versions are available in place.

Simplest option is to use <bindingRedirect /> element under <dependentAssembly /> under <assemblyBinding /> in application configuration file.

For example in a configuration file that is presented below, version 1.0.0.0 of KeyvanAssembly is redirected to version 1.0.0.1.  Using this configuration file, application applies version 1.0.0.1 of KeyvanAssembly rather than version 1.0.0.0.

<configuration>

  <runtime>

    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">

      <dependentAssembly>

        <assemblyIdentity name="KeyvanAssembly"

                          publicKeyToken="f405329a93f8ee7e"

                          culture="en-us" />

        <bindingRedirect oldVersion="1.0.0.0"

                        newVersion="1.0.0.1"/>

      </dependentAssembly>

    </assemblyBinding>

  </runtime>

</configuration>

A nice point is you can force your application to redirect all available versions of an assembly to a specific version using "*" wildcard:

<configuration>

  <runtime>

    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">

      <dependentAssembly>

        <assemblyIdentity name="KeyvanAssembly"

                          publicKeyToken="f405329a93f8ee7e"

                          culture="en-us" />

        <bindingRedirect oldVersion="*"

                        newVersion="1.0.0.2"/>

      </dependentAssembly>

    </assemblyBinding>

  </runtime>

</configuration>

Now playing: Vangelis - Pulstar

4 Comments

Fahrenheit Marketing is your resource for Search Engine Optimization in Austin.


Rui Silva
Jan 05, 2007 5:57 AM
#
Hi, I know that it is possible, with .net 2.0, to configure an application to run against a newer version of an assembly with: but i can't do the opposite way, that is: i'm right? Why? I think that with .net 1.1 the second scenario was also acomplished. best regards, Rui

fm164
Dec 08, 2008 3:39 PM
#

Hi,

Thanks for the tip.

This looks quite useful, though it did not work for me when I tried it... Is there anything else that is needed to be able to use the "*" wildcard?

Thank you


Pierre-Alain Vigeant
Mar 31, 2009 11:00 AM
#

You cannot specify a * for oldVersion, but you can specify a range.

The following will redirect everything before version 2.0.0.0 to the version 2.0.0.0:

<bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0"/>


Himani
Dec 17, 2009 4:01 AM
#
Hi,
I have a sharepoint web applicaition containing two site collections. Both reference different versions of the DLL in gac.
I need to specify the version to use in the assemblies section. But as soon as I do that, the other site breaks down. So, I tried to place binding redirect so that erquest for the old version go to the old version. but somehow it doesnt work. It still shows me the same error (that the type exists in both verisons). If i remove the assemby name from assemblies seciton then the other iste works and the first one stops working which is using the newer veriosn. Please help!

Leave a Comment





Ads Powered by Lake Quincy Media Network