Studies show that good grammar leads to more promotions and higher salaries. Write with Grammarly

C# Error CS0426 – The type name ‘identifier’ does not exist in the type ‘type’

C# Compiler Error

CS0426 – The type name ‘identifier’ does not exist in the type ‘type’

Reason for the Error

You’ll get this error in your C# code when you are trying to reference a type nested within another type where the nested type doesnot exist.

For example, lets try to compile the below code snippet.

using System;

namespace DeveloperPublishNamespace
{
    public class MainA
    {
    }

    class Program
    {      
        static void Main(string[] args)
        {
            MainA obj = new MainA();
            MainA.C onj1 = null;
            Console.WriteLine("Hello World!");
        }
    }
}

You’ll receive the error code CS0426 when you try to compile the above C# program because the nested type C doesnot exist in the class MainA and you are trying to reference them in your Main function.

Error CS0426 The type name ‘C’ does not exist in the type ‘MainA’ DeveloperPublish C:\Users\Senthil\source\repos\ConsoleApp4\ConsoleApp4\Program.cs 14 Active

C# Error CS0426 – The type name 'identifier' does not exist in the type 'type'

Solution

You can avoid this error in your C# code by verifying the name that is used and that the type that you are referencing exists in the Main class.