referrring to a vb.net-declared namespace from c# class

S

SC

i have 2 separate projects:

1) Project A: Class library, written in VB.NET; It's namespace is
explicitly defined in the code like:

Namespace MyCompany.Project.ClassesA
....
End Namespace

2) Project B: Classes written in C#. It looks like:

using MyCompany.Project.ClassesA; <-----------ERROR

namespace MyCompany.Project.ClassesB {
....
}

The problem is that I get an error message:

The type or namespace name 'ClassesA' does not exist in the class or
namespace MyCompany.Project' (are you missing an assembly reference?)

I've referenced it in my References but for some reason the compiler
seems to get confused when my namespaces have "."!!!

Has anyone had this problem? I've even created a project C in VB.NET
to reference ClassesA and it's worked out fine. Just when the caller
is in C# do i have this issue.

HELP!!!

Thanks!
 
N

Nicholas Paldino [.NET/C# MVP]

SC,

I think that you might not have added the reference correctly. I
created a VB class library with the namespace that you specified
("MyCompany.Project.ClassesA"), and then I created a Windows Application in
C#, using the other namespace ("MyCompany.Project.ClassesB") and it compiled
just fine.

Are you sure that you set the reference correctly to the assembly
containing the classes from the first namespace?
 
P

Patrick Steele [MVP]

i have 2 separate projects:

1) Project A: Class library, written in VB.NET; It's namespace is
explicitly defined in the code like:

Namespace MyCompany.Project.ClassesA
...
End Namespace

2) Project B: Classes written in C#. It looks like:

using MyCompany.Project.ClassesA; <-----------ERROR

namespace MyCompany.Project.ClassesB {
...
}

The problem is that I get an error message:

The type or namespace name 'ClassesA' does not exist in the class or
namespace MyCompany.Project' (are you missing an assembly reference?)

I've referenced it in my References but for some reason the compiler
seems to get confused when my namespaces have "."!!!

Has anyone had this problem? I've even created a project C in VB.NET
to reference ClassesA and it's worked out fine. Just when the caller
is in C# do i have this issue.

Try using ILDASM to view the namespace in the VB.NET assembly. VB.NET
projects have a "default namespace" that is appended to the namespaces
declared in code. It makes it confusing to find the "true" fully
qualified name.
 
M

Marina

VS.NET deals with VB a little differently. In the properties for the
project (common properties -> General), you will see a root namespace field.
By default it is the name of the project.

This means, that whatever other namespaces you defined, they will be placed
inside this namespace.

So you need to blank this out, then there is no root namespace, and it will
generate the correct namespaces.

You can use the object browser to see exactly what namespaces are available
in your project,.
 

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