tags:

views:

1003

answers:

5

I have two assemblies with the same name in the Global Assembly cache, but with different version numbers. How do I tell my program which version to reference?

For the record, this is a VB.Net page in an ASP.Net web site.

+2  A: 

To install an assembly in the GAC you have to give it a strong name. Strong names are never duplicated. So to specify which assembly you want to use you reference it by the strong name.

Joel Coehoorn
+3  A: 

When you add a reference to the DLL in your config file, you specify the version as well as the strong name:

<add assembly="Foo.Bar, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>

or

<add assembly="Foo.Bar, Version=2.5.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>

Ady
+3  A: 

As long as the version number is different (which would be required), you can specify the proper version through your web.config file. This is how I have things setup in one of my apps to reference the proper version of Crystal Reports, since we have multiple versions in the GAC:

<system.web>

   <compilation>
         <assemblies>
            <add assembly="CrystalDecisions.Web, Version=11.5.3700.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304"/>
            <add assembly="CrystalDecisions.Shared, Version=11.5.3700.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304"/>
            <add assembly="CrystalDecisions.ReportSource, Version=11.5.3700.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304"/>
            <add assembly="CrystalDecisions.Enterprise.Framework, Version=11.5.3300.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304"/>
         </assemblies>
      </compilation>

</system.web>
Dillie-O
+6  A: 

Add the assembly to the config file under the assemblies section with version number.

<configuration>
   <system.web>
      <compilation>
         <assemblies>
            <add assembly="System.Data, Version=1.0.2411.0, 
                           Culture=neutral, 
                           PublicKeyToken=b77a5c561934e089"/>
         </assemblies>
      </compilation>
   </system.web>
</configuration>

The add element adds an assembly reference to use during compilation of a dynamic resource. ASP.NET automatically links this assembly to the resource when compiling each code module.

Gulzar
A: 

what if I have different verisons for same assemblies and both are being used by different applications? In that case do I specify anything in assemblies section?

Himani