Click here to Skip to main content
15,891,906 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a Assembly with two different versions , i want to use both assembly in our system with different conditions like old version new version, how can maintain
please give me solution.

Thanks
Posted
Updated 16-Jun-15 0:25am
v2

Add each reference and change their default alias. If you find the assembly under the references node and view its properties you'll see it has an alias of "global". Change that to "newDll" for your new assembly and "oldDll" for your old one. You can now explicitly refer to each assembly via;

oldDll::MyNameSpace.MyClass
newDll::MyNameSpace.MyClass


Or use aliasing in the using list at the top of the page

using OldProduct = oldDll::MyNameSpace.Product;
using NewProduct = newDll::MyNameSpace.Product;


then in your code

OldProduct p = new OldProduct


If you want to simply have our code use different versions of the assembly then update the web.config\app.config file appropriately.
 
Share this answer
 
First of all, I would advise to avoid this situation by all means. Merge all old versions in one, clean up the whole product, don't torture yourself with artificially complicated legacy.

For the resolution of the assembly conflict in the presence of two or more different versions, please see, for example:
http://stackoverflow.com/questions/223195/referencing-different-versions-of-the-same-assembly[^],
http://stackoverflow.com/questions/2460542/using-different-versions-of-the-same-assembly-in-the-same-folder[^].

[EDIT]

Please see the discussion in comments below. Kornfeld Eliyahu Peter reminded me about the extern alias feature. It needs some explanation I tried to provide in my comment below.

—SA
 
Share this answer
 
v3
Comments
Kornfeld Eliyahu Peter 16-Jun-15 6:56am    
I second the warning against to use two versions of the same assembly! Very problematic...
I would add also this link: https://msdn.microsoft.com/en-us/library/ms173212(v=VS.100).aspx
Sergey Alexandrovich Kryukov 16-Jun-15 7:13am    
Thank you very much, Peter.

Technically speaking, .NET is quite capable of using multiple versions and resolution of the references to them and their declarations, but I think this warning should come first.

I forgot to mention extern alias, which I referred to in some past answers. It is absolutely needed in some situations. Say, if assembly A.v1 is used by B, A.v2 is used by C also using B, it is not needed. But if you directly use two assemblies with the same name (two different versions of the same thing or two unrelated assemblies), you need it.

I also need to add that the MSDN documentation is a bit confusing, insufficient. By some reason, under "Visual Studio" documentation, only the compiler's command line option is shown, which is not good enough for Visual Studio use. With Visual Studio, you add one of the references, click on its context menu and introduce one alias name, then do the same with the reference to a different version. Then two alias assembly names can be used in C# as shown in the MSDN example.

I updated my answer.

—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900