Click here to Skip to main content
15,922,015 members
Please Sign up or sign in to vote.
1.80/5 (2 votes)
See more:
Hi,

I have 2 different assembly with same name and namespace.Is there any solution to avoid conflict at the time of adding references of both the dlls.

Can we switch between 2 versions of same assembly using config file.


In my project, I am using these two dlls in two different scenarios.so can we specify dll version before execution.

For first scenario I am using version 1.0 and in second scenario using version 2.0.So is it possible to switch between these two assemblies at run time.

// Dll Version 1.0
namesapace Test
{
class connect
{
int connectTO()
{
// access static data from datatable
}
}
}



// Dll Version 2.0
namesapace Test
{
class connect
{
int connectTO()
{
//access data from database
}
}
}
Posted
Comments
Sergey Alexandrovich Kryukov 1-Oct-14 12:13pm    
The whole idea is bad. Don't do it. Leave only the assembly of one version.
Are all the assemblies involved yours?
—SA

Assuming the assemblies have different names, you might be able to use an "extern alias":
http://blogs.msdn.com/b/ansonh/archive/2006/09/27/774692.aspx[^]
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 1-Oct-14 17:02pm    
Excellent! This information was really hard to find. My big 5.

Nevertheless, this should be considered a a last resort, especially if the referenced assemblies are really different version, not the result of strange coincidence (that's why this feature is little known and hard to discover). I think my warning against actually using this approach is so important, that I decided to put a separate answer. Please see Solution 2.

—SA
Solution 1 is a really excellent answer. Indeed, this is the one of least known features, rarely used, really hard to discover, really can be used to resolve referencing near identical assemblies.

But should it be used to resolve different versions of same assemblies, to use both at the same time? Yes, this is possible, but can only be considered as a last resort. If both versions belong to the development teams, or source codes can be obtained somehow, it would be the best to merge them in one, but usually, there is no a need in that. In nearly all cases, it is already done in the latest version, so a need for using a legacy version, too, would be just mythical. All it takes should be done to migrate to only one version.

Supporting code using two or more options at a time may seem a solution, but even with deficit of development time it cannot be a viable solution, because it post-pones the problem only for short period of time, to make thing a lot worse. Please rethink it all, don't create yourself a big problem.

[EDIT]

Now, the detail from original MSDN source: http://msdn.microsoft.com/en-us/library/ms173212.aspx[^].

This documentation fails to explain all the syntax detail. First of all, this declaration is required to be on top of all the uses clauses.

See also: http://www.dotnetperls.com/extern[^].

—SA
 
Share this answer
 
v3
Comments
Abhilash Gandhewar 2-Oct-14 5:13am    
Thanks for solutions.But I don't want to change in existing code of application which references old version of dll .
Sergey Alexandrovich Kryukov 2-Oct-14 5:57am    
You are welcome.
Excuse me, but "per our requirement" is not a valid argument. Then the person who gave you this "requirement" needs to attend to my advice. If I give advice, I assume that I help a person who can make decisions. As a developer, you have one of the most difficult obligations: too provide feedback on requirements and object in advance if something is wrong. Anyway, I warned you about the consequences; and I have a good reason to do so.

And I recommend you to accept Solutions 1-2 formally (green "Accept" button). I am sure that all together the solutions covers the problem.

—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