Vlad
Vlad

Reputation: 2773

How to add vb classes into the class library?

I made a new VS 2005 class library project and I added several VB.NET classes into it. However, when i compile the project and import the dll into my other projects, I cannot see my classes.

What do i do wrong, what should I do to add then in the compilation?

Upvotes: 2

Views: 1911

Answers (2)

Bart Hofland
Bart Hofland

Reputation: 3905

Did you use an explicit access modifier (Public or Friend) on your classes in your class library? If not, it will default to Friend. That means that your classes are only visible within that assembly (class library).

So you might want to make certain specific classes in your class library public:

Public Class MyClass
    ...
End Class

Edit: As Steven Doggart pointed out, VB.NET classes are public by default. So this might not be an issue unless you explicitly used another access modifier.

Upvotes: 2

Steven Doggart
Steven Doggart

Reputation: 43743

There are multiple reasons why that may happen, so without more information, it's impossible to say for sure why, but the most likely reasons which come to mind are:

  • The classes in the class library may not be declared as Public. If they are declared as Friend (or as Private if they are nested types), they will not be visible to other projects that consume that library. The classes should be declared like this: Public Class MyClass
  • The consuming code is not specifying the namespace. Unless the namespace in which the classes are declared in the class library is the same as the code that's trying to call it, the consuming code needs to either import the class library's namespace, or it needs to fully qualify the class names when it uses them. To import the namespace, at the top of the code file that uses the class, add a line like this: Imports MyClassLibraryNamespace (but with your actual namespace). To fully qualify the class name inline, you can do it like this: Dim myVariable As New MyClassLibraryNamespace.MyClass

Upvotes: 4

Related Questions