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

StackOverflow https://stackoverflow.com/questions/244431

  •  04-07-2019
  •  | 
  •  

Question

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.

Was it helpful?

Solution

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>

OTHER TIPS

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.

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

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top