PC Review


Reply
Thread Tools Rate Thread

Class name conflict

 
 
qglyirnyfgfo@mailinator.com
Guest
Posts: n/a
 
      23rd Jun 2008
Suppose that you have two dlls (ClassLibrary1.dll and
ClassLibrary2.dll).

Now suppose that both dlls have the same class declared on them using
the exact same name space and class name, for example, supposed both
dlls have the following snippet of code:

namespace SomeNameSpace
{
public class Class1
{
}
}

Now supposed you reference both dlls into your main project and add
the following snippet of code into this main project.

SomeNameSpace.Class1 cls = new SomeNameSpace.Class1();

If you try to compile the project you will get an error message
stating that “SomeNameSpace.Class1()” exist in both dlls and so the
compiler can’t choose which one to select.

Is there a way to specify what dll to use when instantiating Class1?

Thank you.
 
Reply With Quote
 
 
 
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      23rd Jun 2008
On Jun 23, 3:28*pm, qglyirnyf...@mailinator.com wrote:
> Suppose that you have two dlls (ClassLibrary1.dll and
> ClassLibrary2.dll).
>
> Now suppose that both dlls have the same class declared on them using
> the exact same name space and class name, for example, supposed both
> dlls have the following snippet of code:
>
> namespace SomeNameSpace
> {
> * * public class Class1
> * * {
> * * }
>
> }
>
> Now supposed you reference both dlls into your main project and add
> the following snippet of code into this main project.
>
> SomeNameSpace.Class1 cls = new SomeNameSpace.Class1();
>
> If you try to compile the project you will get an error message
> stating that “SomeNameSpace.Class1()” exist in both dlls and so the
> compiler can’t choose which one to select.
>
> Is there a way to specify what dll to use when instantiating Class1?


Yes, assuming you're using C# 2 or later. You need to use a feature
called "extern aliases" - that should be enough to get you going with
a good search. However, I'd stress that if you can *possibly* avoid
this, do so.

Jon
 
Reply With Quote
 
Marc Gravell
Guest
Posts: n/a
 
 
Reply With Quote
 
Jeff Winn
Guest
Posts: n/a
 
      24th Jun 2008
I have to agree with Jon, you should avoid reusing the same namespace and
type name repeatedly.

"Jon Skeet [C# MVP]" <(E-Mail Removed)> wrote in message
news:05badf78-c79a-465b-bf38-(E-Mail Removed)...
On Jun 23, 3:28 pm, qglyirnyf...@mailinator.com wrote:
> Suppose that you have two dlls (ClassLibrary1.dll and
> ClassLibrary2.dll).
>
> Now suppose that both dlls have the same class declared on them using
> the exact same name space and class name, for example, supposed both
> dlls have the following snippet of code:
>
> namespace SomeNameSpace
> {
> public class Class1
> {
> }
>
> }
>
> Now supposed you reference both dlls into your main project and add
> the following snippet of code into this main project.
>
> SomeNameSpace.Class1 cls = new SomeNameSpace.Class1();
>
> If you try to compile the project you will get an error message
> stating that “SomeNameSpace.Class1()” exist in both dlls and so the
> compiler can’t choose which one to select.
>
> Is there a way to specify what dll to use when instantiating Class1?


Yes, assuming you're using C# 2 or later. You need to use a feature
called "extern aliases" - that should be enough to get you going with
a good search. However, I'd stress that if you can *possibly* avoid
this, do so.

Jon

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't specify a location for new class code file on class diagram>new class dialog? Andy B Microsoft C# .NET 3 14th Feb 2008 01:57 AM
Synchronization conflict message but no conflict table in list =?Utf-8?B?U2NhblZhY2M=?= Microsoft Access 1 28th Dec 2005 05:48 PM
Namespace and Class name conflict Wayne Microsoft C# .NET 1 3rd Oct 2005 08:37 PM
driver conflict with XP: possibly video? but certified.. exact conflict unknown seth thomas rasmussen Windows XP Drivers 9 8th Dec 2003 10:26 PM
activex ,money tree dialer,RdxE Class,updaate class,YInstStarter Class damaged RUSSELL Windows XP Performance 1 23rd Nov 2003 02:05 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:19 AM.