DetailPage-MSS-KB

Microsoft small business knowledge base

Article ID: 304260 - Last Review: December 6, 2006 - Revision: 4.5

This article was previously published under Q304260

On This Page

SYMPTOMS

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
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:
  1. 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.
  2. 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.

MORE INFORMATION

Steps to Reproduce Behavior

  1. Create a new Visual Basic .NET or Visual Basic 2005 console application.
  2. In Module1.vb, at the top of the code file, add the following statement:
    Imports System.Drawing
    					
  3. 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.

REFERENCES

Error reference
http://msdn.microsoft.com/en-us/library/bb851605.aspx (http://msdn.microsoft.com/en-us/library/bb851605.aspx)

APPLIES TO
  • Microsoft Visual Basic 2005
  • Microsoft Visual Basic .NET 2003 Standard Edition
  • Microsoft Visual Basic .NET 2002 Standard Edition
Keywords: 
kbvs2005swept kbvs2005applies kbprb kbprod2web KB304260
Share
Additional support options
Ask The Microsoft Small Business Support Community
Contact Microsoft Small Business Support
Find Microsoft Small Business Support Certified Partner
Find a Microsoft Store For In-Person Small Business Support