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???
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.
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.