Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using different versions of the same assembly in the same folder

I have the following situation

Project A

 - Uses Castle Windsor v2.2  - Uses Project B via WindsorContainer 

Project B

 - Uses NHibernate  - Uses Castle Windsor v2.1 

In the bin folder of Project A I have the dll Castle.DynamicProxy2.dll v2.2 and NHibernate dlls. Now the problem is that NHibernate is dependent on Castle.DynamicProxy2.dll v2.1 which is not there. How do I resolve this situation.

like image 772
Hemanshu Bhojak Avatar asked Mar 17 '10 07:03

Hemanshu Bhojak


People also ask

Can multiple versions of the assembly can live side by side?

Because the strong-named assembly's version number is part of its identity, the runtime can store multiple versions of the same assembly in the global assembly cache and load those assemblies at run time.

What is assembly C#?

An assembly is a collection of types and resources that are built to work together and form a logical unit of functionality. Assemblies take the form of executable (.exe) or dynamic link library (. dll) files, and are the building blocks of . NET applications.


2 Answers

I used the following configuration to resolve the issue.

<configuration>     <runtime>         <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">             <dependentAssembly>                 <assemblyIdentity name="Castle.DynamicProxy2" publicKeyToken="407dd0808d44fbdc" />                 <codeBase version="2.1.0.0" href="v2.1\Castle.DynamicProxy2.dll" />                 <codeBase version="2.2.0.0" href="v2.2\Castle.DynamicProxy2.dll" />             </dependentAssembly>             <dependentAssembly>                 <assemblyIdentity name="Castle.Core" publicKeyToken="407dd0808d44fbdc" />                 <codeBase version="1.1.0.0" href="v2.1\Castle.Core.dll" />                 <codeBase version="1.2.0.0" href="v2.2\Castle.Core.dll" />             </dependentAssembly>         </assemblyBinding>     </runtime> </configuration> 
like image 162
Hemanshu Bhojak Avatar answered Oct 18 '22 05:10

Hemanshu Bhojak


One thing very, very, very important that one might miss if he is not paying enough attention.

The assembly you write in the codeBase version tag, must be strong named.

From the following link: http://msdn.microsoft.com/en-us/library/efs781xb.aspx

For assemblies without a strong name, version is ignored and the loader uses the first appearance of <codebase> inside <dependentAssembly>. If there is an entry in the application configuration file that redirects binding to another assembly, the redirection will take precedence even if the assembly version doesnt match the binding request.

like image 37
Lauro Wolff Valente Sobrinho Avatar answered Oct 18 '22 06:10

Lauro Wolff Valente Sobrinho