C# Error CS0101 – The namespace ‘namespace’ already contains a definition for ‘type’

C# Compiler Error

CS0101 – The namespace ‘namespace’ already contains a definition for ‘type’

Reason for the Error

You will receive this error when your namespace has duplicate identifiers that is declared.

For example, the below code snippet contains the namespace DeveloperPublish but contains two classes with the same name “Class1”.

namespace DeveloperPublish
{
    class Class1
    {

    }

    class Class1
    {

    }
    public class Program
    {
        public static void Main()
        {

        }
    }
}

This will result with the error.

Error CS0101 The namespace ‘DeveloperPublish’ already contains a definition for ‘Class1’ ConsoleApp2 C:\Users\admin\source\repos\ConsoleApp2\ConsoleApp2\Program.cs 8 Active

C# Error CS0101 – The namespace 'namespace' already contains a definition for 'type'

Solution

To fix the error, rename or delete one of the duplicate identifiers. If it is a class, try moving it to a different namespace.

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