Global namespace problem

G

Guest

I have 2 external assemblies A1 and A2 that both define class X in the global
namespace. I need to use both assemblies in my VB project but the names X are
ambiguous. How can I get around this problem?

Is there a way to refer to the assembly, f.ex. A1.X and A2.X (this syntax
does not compile).

Or can I change the name X in the Imports directive? Again the problem is
how do I refer to the 2 different X'es in assemblies A1 and A2:

Imports A1_X = A1.X ' Does not compile

BTW, is there any way to explicitly refer to the global namespace, like C++
::?

Any bright ideas out there?
 
A

Armin Zingler

anders said:
I have 2 external assemblies A1 and A2 that both define class X in
the global namespace. I need to use both assemblies in my VB project
but the names X are ambiguous. How can I get around this problem?

Is there a way to refer to the assembly, f.ex. A1.X and A2.X (this
syntax does not compile).

Or can I change the name X in the Imports directive? Again the
problem is how do I refer to the 2 different X'es in assemblies A1
and A2:

Imports A1_X = A1.X ' Does not compile

BTW, is there any way to explicitly refer to the global namespace,
like C++ ::?

Any bright ideas out there?


Did you leave the "root namespace" of the two assemblies empty? If you
didn't, you can use the full qualified name.


Armin
 
G

Guest

Armin, how do you set the root namespace? I get very confused regarding the
namespace heirchy
 
G

Guest

Can you elaborate, please. You have lost me!

Armin Zingler said:
Did you leave the "root namespace" of the two assemblies empty? If you
didn't, you can use the full qualified name.


Armin
 
A

Armin Zingler

anders said:
Can you elaborate, please. You have lost me!

In each assembly, you can set the "root namespace" in the project
properties. That's the namespace all classes and namespaces are placed in.
If you left them (in both projects) empty, you probably really have got a
problem because the full qualified name is the same. If you didn't leave it
empty, you could use the full qualified name to specify the class. If A1 ist
the root namespace of assembly A1, then A1.X is the full qualified class
name of the class in assembly A1.


Armni
 
P

Phill. W

anders said:
I have 2 external assemblies A1 and A2 that both define class X in
the global namespace. I need to use both assemblies in my VB project
but the names X are ambiguous. How can I get around this problem?

Either fully-qualify all references to each class, as in

sData = NS1.NS2.NS3.X.StringMethod()
sData = NS4.NS5.NS6.X.StringMethod()

or change the Imports statements so add your own "alias", as in

Imports A1=NS1.NS2.NS3
Imports A2=NS4.NS5.NS6

sData = A1.X.StringMethod()
sData = A2.X.StringMethod()

(I use the same thing with the VisualBasic namespace, just to jog my
memory about the potential differences, as in

sItems = VB.Split( "string with line breaks", vbCrLf )

HTH,
Phill W.
 
G

Guest

I found that if I don't specifically provide a root namespace, then when I
create a new project, the name of the directory if used.
 
G

Guest

A1 and A2 are OEM products so I don't have the source code or project files
to fiddle with. This begins to look like a serious problem in .NET languages.
The VB.NET Imports directive gives you the possibility to resolve name
clashes between named namespaces but NOT clashes within the global namespace!

I also looked into C# and Managed C++ and could not find any solution to
this problem.
 
G

Guest

You don't seem to answer my question. How do you fully qualify X which is in
the global namespace of both assemblies A1 and A2?
 
A

Armin Zingler

anders said:
A1 and A2 are OEM products so I don't have the source code or
project files to fiddle with. This begins to look lik
easeriousproblemin.NETlanguages. The VB.NET Imports directive gives
you the possibility to resolve name clashes between named namespaces
but NOT clashes within the global namespace!

I also looked into C# and Managed C++ and could not find any
solution to this problem.


I do not really see the problem. I do not even have the possibilty to set
references to two assemblies containing conflicting class names because I
get this error:

"bla\ClassLibrary2\Class1.vb(1): class "Class1" and class "Class1", defined
in "bla\ClassLibrary1\Class1.vb", conflict in namespace "<Default>""

You get this message if you create a new project, add two new
classlibraries, delete the root namespace in both libraries and try to set a
reference from the main project to both classlibraries.


Are you sure that the classes are not contained in a namespace in both
assemblies? Have a look @ the object browser.



Armin
 
P

Phill. W

Define "OEM products".

If these are commerical products that are shipping /without/ using
well-defined Namespaces, I'd think long and hard before making use
of them.

If you have no other recourse, you may have to write your own,
(properly Namespaced) "wrapper" assembly around one or other
of them, exposing all the same properties, method, etc.

Regards,
Phill W.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top