Search code examples
vb.netdllvisual-studio-2005class-library

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?


Solution

  • 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