How to use multiple versions of assembly

1. Create 2 shared assemblies with different versions (1.0.0.0 and 2.0.0.0).

2. For assembly 1 include the following reference in project file.
   
      ..\..\TestAssembly\T1\TestAssembly.dll
      Test1
      False
   

**Hint Path Vs Reference Path
**As for the "Referece Path" or "Hint Path" in the VS.NET project's setting
files, they're all design-time /dev-time setting used by the IDE. As
described in the IDE's help doc, "Reference Path" are used by the VS.NET
IDE to load all the assembliy references when the Project is loaded into
the VS.NET IDE. And the "Hit Path" is mainly used for building time, when
the IDE will build the project, it'll locate the assemblies which is
required to link through the "Hint Path". Anyway, they're all internally
used by the VS.NET IDE, and is possibly to change in sequential version and
they have nothing to do with the .NET framework CLR's runtime assembly
locating.

For .net framework CLR's runtime assembly locating, it'll follow a well
defined steps, generally, it'll check GAC (if strong-named) first, then,
codebase settting , and private path probing. Here is a MSDN reference
which describing the .NET framework's runtime assembly locating.

3. Form assembly 2 include the following reference in the project file.
   
      ..\..\TestAssembly\T2\TestAssembly.dll
      Test2
      False
   

4. While refering the above assemblies set extern aliases for both the assemblies
      extern alias Test1;      extern alias Test2;

5. And then we can use Test1 and Test2 as 2 different namespaces
      Test1.TestAssembly.TestClass t1 = new Test1.TestAssembly.TestClass();
      MessageBox.Show(t1.Add(2, 3).ToString());

      Test2.TestAssembly.TestClass t2 = new Test2.TestAssembly.TestClass();
      MessageBox.Show(t2.Add(2, 3, 4).ToString());

Please note the project referencing both the assemblies will be compiled with the following warnings.

Warning 1 
No way to resolve conflict between "TestAssembly, Version=2.0.0.0, Culture=neutral, PublicKeyToken=275b13b4e9b16f25" and "TestAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=508b5c5f7455410a". Choosing "TestAssembly, Version=2.0.0.0, Culture=neutral, PublicKeyToken=275b13b4e9b16f25" arbitrarily. WindowsApplication1

Warning 2 
The referenced component 'TestAssembly' could not be found.

Above scenario is about when we refer both the assemblies of (same name different versions) in the same code file ..but what if we want to override the functionality of an assembly ver 1.0 with ver 2.0.

put following  tag under configuration settings in the aplication's config file.

<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="<assemblyName>" publicKeyToken="<publicKeyToken>" culture="<****culture>" />

</dependentAssembly>
</assemblyBinding>
</runtime>

This article is part of the GWB Archives. Original Author: Narendra Tiwari

New on Geeks with Blogs

  • We Won The One Award I Actually Care About

    Full Scale made the Inc. 5000 for the fifth year straight, the 12th listing across my three companies. Here is why the one award you cannot buy is worth stopping for.

  • Your Customers Build the Features Now

    I let a tool I liked sit dead for a year rather than build the features I wanted. An MCP server meant I never had to, and your customers can do the same to your product.

  • Get the Size of a Directory in Linux the Easy Way

    du -sh for the quick answer, ncdu for the cleanup, df for the disk itself: every command for checking directory size in Linux, plus why du and df never agree.

  • Vim Search and Replace: The Ultimate Guide

    One :%s command replaces every match in a file before a find dialog would even open. The Vim substitute patterns worth the muscle memory: flags, ranges, capture groups, and multi-file edits.