C# Error CS0234 – The type or namespace name ‘name’ does not exist in the namespace ‘namespace’

C# Compiler Error

CS0234 – The type or namespace name ‘name’ does not exist in the namespace ‘namespace’ (are you missing an assembly reference?)

Reason for the Error

You will usually see this error in your C# program when you try to reference an assembly that is not part of your project or you have referred to an class by specifying the namespace and the class is misspelt or doesnot exist.

For example, try to compile the below code snippet.

namespace DeveloperPubNamespace
{
    public class Employee
    {
        public string SurName { get; set; }
    }
    class Program
    {
        public static void Main()
        {
            DeveloperPubNamespace.Employe emp = new DeveloperPubNamespace.Employe();
        }
    }
}

This program will result with the C# error code CS0234 because the DeveloperPubNamespace doesnot have the class Employe.

Error CS0234 The type or namespace name ‘Employe’ does not exist in the namespace ‘DeveloperPubNamespace’ (are you missing an assembly reference?) DeveloperPublish C:\Users\Senthil\source\repos\ConsoleApp3\ConsoleApp3\Program.cs 11 Active

Solution

To fix the error code CS0234 in C#, just ensure that your project has correct references and the class that you are trying to access via the namespace exists. Try using the Object Browser to verify if the assembly contains the type that you are using.

namespace DeveloperPubNamespace
{
    public class Employee
    {
        public string SurName { get; set; }
    }
    class Program
    {
        public static void Main()
        {
            DeveloperPubNamespace.Employee emp = new DeveloperPubNamespace.Employee();
        }
    }
}

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

C# Compiler Error CS0442 – ‘Property’: abstract properties cannot have private accessors Reason for the Error You’ll get this error...
This is a really simple one . Below is a simple example of an enum called “Designation” defined with the...
This blog post explain the usage of the Checked Block in .NET and how you can use them in Visual...