-2

I'm creating a class library in VS2019 (VB.NET).

In the project properties, I used this root namespace: Customer.App.Classlibrary

When I'm compiling and using this library in another project, I need to import it as

Import Customer.App.Classlibrary.Customer.App.Classlibrary

The root namespace is duplicated....

Any suggestions???

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490

1 Answers1

0

Unlike c#, in vb.net you don't need a namespace around your class, rather all vb.net code starts in the root namespace without specifying one. So when you have written your function to be used like this

Namespace Customer.App.Classlibrary

    Public Module MyStaticCLass
        Public Sub Foo()

        End Sub
    End Module

End Namespace

the namespace Customer.App.Classlibrary is added to the root namespace.

enter image description here

and your namespace becomes RootNamespace.ClassNamespace = Customer.App.Classlibrary.Customer.App.Classlibrary

and you need to do

Imports Customer.App.Classlibrary.Customer.App.Classlibrary

The fix: just remove the namespace from your class definition

'Namespace Customer.App.Classlibrary

Public Module MyStaticCLass
    Public Sub Foo()

    End Sub
End Module

'End Namespace

and the imports will simply be

Imports Customer.App.Classlibrary

It might be a better idea to specify the root namespace to Customer and you can put your class in Namespace App.Classlibrary which will have a similar effect, with the added benefit of being able to separate classes in the same assembly into more granular namespaces. This depends on your desired design.

djv
  • 15,168
  • 7
  • 48
  • 72
  • It worked as you said on normal classes. I just noticed, the issue is caused by a EDMX Model, that adds the extra name space. – Hugo Flores Feb 26 '20 at 22:18