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.

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...