Microsoft KB Archive/304260

= You may receive an error message when you use an invalid namespace in Visual Basic .NET or in Visual Basic 2005 =

Article ID: 304260

Article Last Modified on 12/6/2006

-

APPLIES TO


 * Microsoft Visual Basic 2005
 * Microsoft Visual Basic .NET 2003 Standard Edition
 * Microsoft Visual Basic .NET 2002 Standard Edition

-



This article was previously published under Q304260



SYMPTOMS
When you compile your application in Visual Basic .NET, you receive the following compiler error message:

The Namespace or type   for the Import   cannot be found.

In Visual Studio 2005, you receive the following compiler error message:

Namespace or type specified in the Imports   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   is the name of the namespace you are trying to import, and   is the fully qualified namespace that you are using in your Imports statement. For example, the code Imports System.MyNamespace 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.



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



RESOLUTION
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: Imports System.Data.SqlClient 



STATUS
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: Imports System.Drawing </li> 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.</li></ol>

<div class="references_section">