Cry about...
.NET / C# Troubleshooting


The type or namespace name 'some-name' does not exist in the namespace 'some-namespace' (C#)


Symptom:

When compiling a C# application the compiler generates the following error:

The type or namespace name 'some-name' does not exist in the namespace 'some-namespace' (are you missing an assembly reference?)

where 'some-name' is the name of a type or a namespace and 'some-namespace' is the name of a namespace. For example:

The type or namespace name 'UI' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)

Possible Causes and Remedies:

  • The most likely cause is a simple spelling mistake.

    For example:

    using System.Webb;

    will generate "The type or namespace name 'Webb' does not exist in the namespace 'System' (are you missing an assembly reference?) but in this case it should be:

    using System.Web;

  • Otherwise, like the error says, you are probably missing an assembly reference.

    Each project (be it an application or a class library) contains references which might be to other class libraries or libraries which are provided as part of the .NET framework. So check the list of references for the project these are shown in the Solution Explorer under "References" in the tree view (or for VB.Net they are shown on the "References" tab of the project properties).

    If the reference is not listed then add it. For example if I have "using System.Web;" in my code then a reference to System.Web needs to be listed. It will be by default for web projects but will not by default for class libraries. Simply right click the "References" title in Solution Explorer and select "Add reference..." (or for VB.Net click [Add...] when viewing the list of references in the project properties).

    When adding a reference the "Projects" tab contains (as you would expect) a list of projects in the solution, and the ".NET" tab contains all the projects available from the .NET framework or which have been added to the GAC. Unfortunately the contents of ".NET" tab are not sorted alphabetically, which can make finding the necessary reference difficult.

    If you still cannot find the reference listed then an alternative approach is to browse for it. The following table lists the location of various namespaces:

    Namespace Assembly file
    System.Web.UIC:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Web.dll
    System.Web.UI.WebControlsC:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Web.dll

    I expect to add to this table slowly over time.

  • See also: The type or namespace name '<type-name>' could not be found (C#)

These notes are believed to be correct for C# for Visual Studio 2010 Professional, and may apply to other versions as well.



About the author: is a dedicated software developer and webmaster. For his day job he develops websites and desktop applications as well as providing IT services. He moonlights as a technical author and consultant.