Geeks With Blogs

News
Employers
Soppa Group India
iSmart Panache Inc
R Systems Internationals Ltd
Technovate eSolutions Pvt Ltd
The contents of this blog are my personal opinion and do not represent in any way the view of my employer.
These postings are provided "AS IS" with no warranties, and confer no rights.

Google PR™ - Post your Page Rank with MyGooglePageRank.com

Narendra Tiwari

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.
    <Reference Include="TestAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=508b5c5f7455410a, processorArchitecture=MSIL">
      <HintPath>..\..\TestAssembly\T1\TestAssembly.dll</HintPath>
      <Aliases>Test1</Aliases>
      <Private>False</Private>
    </Reference>

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.
    <Reference Include="TestAssembly, Version=2.0.0.0, Culture=neutral, PublicKeyToken=275b13b4e9b16f25, processorArchitecture=MSIL">
      <HintPath>..\..\TestAssembly\T2\TestAssembly.dll</HintPath>
      <Aliases>Test2</Aliases>
      <Private>False</Private>
    </Reference>

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 <runtime> 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>" />
<!--<assemblyIdentity name="TestAssembly" publicKeyToken="5ce1b9763dbb3e84" culture="neutral" />->
<
bindingRedirect oldVersion="<oldVersion>" newVersion="<newVersion>" />
<!--<bindingRedirect oldVersion="1.0.0.0" newVersion="1.1.0.0" />-->
</
dependentAssembly>
</
assemblyBinding>
</
runtime>

Posted on Tuesday, November 11, 2008 9:38 AM .Net | Back to top


Comments on this post: How to use multiple versions of assembly

# re: How to use multiple versions of assembly
Requesting Gravatar...
it's good post but I tried with VS 2010 and didn't work for me. it takes only one .dll at a time and so I can't even create second alias. any idea?
Left by Ash on Feb 02, 2012 3:31 AM

# re: How to use multiple versions of assembly
Requesting Gravatar...
thanks for the post. I'v tried it with VSS 2010 and VSS 2008. It didn't work. Could you please provide a sample zip.

Left by Manifredo on Apr 11, 2012 4:39 PM

Your comment:
 (will show your gravatar)


Copyright © Narendra Tiwari | Powered by: GeeksWithBlogs.net