Microsoft KB Archive/304656

= PRB: Compiler Error CS0246: The Type or Namespace Name  Could Not be Found =

Article ID: 304656

Article Last Modified on 10/30/2002

-

APPLIES TO


 * Microsoft Visual C# .NET 2002 Standard Edition

-



This article was previously published under Q304656



SYMPTOMS
When you compile your code you receive the following error message:

The type or namespace name  could not be found (are you missing a using directive or an assembly reference?)

where  is the name of the type or namespace you are trying to use.



CAUSE
There are several reasons why you might be receiving this error:   You might have misspelled the name of the type or namespace that you are trying to use. Without the correct name, the compiler is unable to find the definition for the type or namespace that you referred to in your code. This occurs most often because C# is case-sensitive and you did not use the correct capitalization when you referred to the type. For example, see the following code: Dataset ds; This will generate compiler error CS0246. Notice the 's' in Dataset is not capitalized.   If the error is a reference to a namespace, you may not have the assembly where the namespace is located referenced in your project. For example, you might be using the following namespace: using Accessibility; However, if you don't have the assembly Accessibility.dll referenced in your project then you will receive compiler error CS0246.   If the error is a reference to a type, then you may not have the proper using directive, or you may have not fully qualified the name of the type. See the following line of code: DataSet ds; To be able to use the DataSet type you need two things. First, you need a reference to the assembly that contains the definition for the DataSet type. Second, you need a using directive for the namespace where DataSet is located. For example, because DataSet is located in the System.Data namespace, you would need the following statement at the beginning of your code file: using System.Data; The second step is not required. However, if you omitted this step, then you would have to fully qualify the DataSet type when you refer to it. Fully qualifying it means that you use the namespace AND type each time that you refer to it in your code. So, if you decided to forgo the second step, you would have to change your declaration code to: System.Data.DataSet ds; 



RESOLUTION
When you receive this compiler error, the first thing to check is spelling. As previously noted, the most common cause is not having the correct case for the type or namespace. If you feel certain that you have spelled the name of the type or namespace correctly (including the correct capitalization), then check the following:  Assembly Reference:

Make sure that you have referenced the assembly that contains the namespace. If you are developing in Visual Studio .NET, you can go to the Project menu and click Add Reference. On the .NET tab, choose the assembly that contains the namespace that you are trying to import, or Browse to the folder that contains the assembly. If you are using the command-line compiler, add the appropriate switch (/reference) to the compile statement.</li>  Namespace:

Make sure that you are importing the namespace into your project by having a using statement at the top of the code file that contains the type reference, such as: using System.Data; If you don't have the using statement, then fully qualify the reference to the type: System.Data.DataSet ds; </li></ol>

<div class="status_section">

STATUS
This behavior is by design.

Keywords: kbprb kbcompiler kbprod2web KB304656

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.