Electrons_Ahoy
Electrons_Ahoy

Reputation: 38643

If I have two assemblies with the same name in the GAC, how do I tell .Net which to use?

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.

Upvotes: 3

Views: 7991

Answers (4)

Ady
Ady

Reputation: 4736

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"/>

Upvotes: 3

Gulzar Nazim
Gulzar Nazim

Reputation: 52198

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.

Upvotes: 6

Dillie-O
Dillie-O

Reputation: 29745

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>

Upvotes: 5

Joel Coehoorn
Joel Coehoorn

Reputation: 416121

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.

Upvotes: 2

Related Questions