3

I have a WebApplication project called WebApp and I have a Library Project called LibProj where I define a namespace like

Namespace LibProj
    Public Class Employee
        Public Property Name As String
    End Class
End Namespace

Now I add the reference to WebApp and try to use the namespace with

Imports LibProj

but this does not work. I have to add

Imports LibProj.LibProj

In all the examples I studied it always works with Imports LibProj instead but I just cannot see what is wrong with my procedure. Could anyone help me here?

1
  • Maybe your project is named LibProj too? Commented Apr 27, 2015 at 12:53

2 Answers 2

7

In VB, you don't need to specify a namespace in each file - it will take on the root namespace of the project.

These root namespaces have the same name (by default) as the project they're in, so your root namespace will be LibProj already. By adding the Namespace statement in your code, you're adding a sub-namespace to the root namespace.

If you want to create new namespaces outside of your root namespace, prepend it with Global, eg:

Namespace Global.SomeOtherLib
  '...
End Namespace

This is then no longer part of the root namespace of your project.

You can find and edit the root namespace of your project by going to the project properties, within the Application section.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your answer! Now I understand the difference between the c# code and the translation I have to make concering the namespaces. Great answer!
0

Each project already has a root Namespace which by default is the same as the name of the project (LibProj in this case). When you declare a Namespace for your class (LibProj in this case) that is assumed to be a sub-Namespace within the project's root Namespace. So you have declared the Namespace to be LibProj.LibProj.

If you are happy with all the classes in your project being in the LibProj Namespace, then you don't need to specify the Namespace in each class definition.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.