Edit

Share via


Compiler Error CS0101

The namespace 'namespace' already contains a definition for 'type'

A namespace has duplicate identifiers. Rename or delete one of the duplicate identifiers. For more information, see Namespaces

The following sample generates CS0101:

C#
// CS0101.cs  
namespace MyNamespace  
{  
   public class MyClass  
   {  
      static public void Main()  
      {  
      }  
   }  
  
   public class MyClass   // CS0101  
   {  
   }  
}  

A CS0101 is also generated when your class name clashes with your namespace name. This can happen when expanding with helper classes for the base class where you attempt to keep the namespace route the same. In the below example, the UTF8 class should clearly be a subsidiary of the String class, but attempting to force it into the same name space by declaring said namespace as Utilities.String will cause a CS0101 error:

C#
//CS0101-Utilities.String.cs
namespace Utilities
{  
   public class String
   {  
        public string MyString;
   }  
}

//CS0101-Utilities.String.UTF8.cs
namespace Utilities.String  // CS0101  
{  
   public class UTF8
   {  
        public string MySecondString;
   }  
}