h1

Configuring Applications – Part 1 : Assembly Redirection

May 7, 2007

 

.NET Framework gives the control and flexibility over the way applications run. We can have the control over the resources accessed, which versions of the assemblies to be used and where remotes objects are located.These settings can be done in the configuration files , avoiding the need to recompile the applications when changes are required.

Locating Assemblies at Runtime:

Here is an article from MSDN that explains about the way runtime framework searches for the assemblies.

This is a sample which shows the configuration to pick assemblies which are at remote site and directories other than the Application Directory

<configuration>
  <runtime>
     <assemblyBinding xmlns=”urn:schemas-microsoft-com:asm.v1″>
       <dependentAssembly>
          <assemblyIdentity name=”myAssembly”
                                      publicKeyToken=”32ab4ba45e0a69a1″
                                      culture=”en-us” />
          <codeBase version=”2.0.0.0″
                           href=”
http://www.somesite.com/myAssembly.dll”/>
        </dependentAssembly>
        <dependentAssembly>
          <assemblyIdentity name=”myAssembly2″
                                      publicKeyToken=”32ab4ba45e0a69a1″
                                      culture=”en-us” />
          <codeBase version=”3.0.0.0″
                           href=”file:=///D:/ProgramFiles/SomeDir/myAssembly2.dll”/>
         </dependentAssembly>
     </assemblyBinding>
  </runtime>
</configuration>

For more detailed article refer to Specifying an Assembly’s Location. It explains about different ways to bind the assembly using the <codebase> and <probing> . This element can be used in the application configuration file, machine configuration file (machine.config), and the publisher policy file.

Leave a Comment