This article was previously published under Q304260
When you compile your application in Visual Basic .NET, you receive the following compiler error message:
The Namespace or type <name> for the Import <import name> cannot be found.
In Visual Studio 2005, you receive the following compiler error message:
Namespace or type specified in the Imports <import name> doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases.
Note <name> is the name of the namespace you are trying to import, and <import name> is the fully qualified namespace that you are using in your Imports statement. For example, the code
might produce one of the following error messages:
The Namespace or type 'MyNamespace' for the Import 'System.MyNamespace' cannot be found.
Namespace or type specified in the Imports System.MyNamespace doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases.
There are two reasons why you might be experiencing this error:
You might have misspelled the name of the namespace that you are trying to import. Without the correct name, the compiler is unable to find the namespace.
You may have spelled the name correctly, but you do not have the assembly where the namespace resides referenced in your project.
To resolve this problem, use the following procedures:
Namespaces are logical groupings of classes that are contained within assemblies. You can think of an assembly as a .dll or .exe file. When you compile a project in Visual Studio .NET, you are creating an assembly. Assemblies can contain multiple namespaces. In order to import a namespace you must first reference the assembly where the namespace resides. To reference the assembly, from the Project menu click Add Reference. On the .NET tab, select the assembly that contains the namespace that you are trying to import, or Browse to the folder that contains the assembly.
Check your imports statement to make sure that you have the correct name of the namespace. Keep in mind that the namespace you want to use might be nested in one or more namespaces. For example, the SqlClient namespace is located in the Data namespace. The Data namespace is located in the System namespace. So, to import the SqlClient namespace you would need to use the following Imports statement:
This behavior is by design.
Steps to Reproduce Behavior
Create a new Visual Basic .NET or Visual Basic 2005 console application.
In Module1.vb, at the top of the code file, add the following statement:
To see the error message, move the mouse pointer over the Imports statement for the namespace or build the project. Notice that you will receive the error because you have not referenced the System.Drawing.dll assembly. If you reference this assembly the error message will disappear.