Skip to content

How to Resolve Error "CS0517: 'class' has no base class and cannot call a base constructor" in C#

Learn how to fix the CS0517 compiler error in C#, which occurs when a class has no base class and attempts to call a base constructor: common in custom runtime development with <NoStdLib>true or corrupted project settings.

The Compiler Error CS0517 is a foundational logic error. The message reads: "'MyClass' has no base class and cannot call a base constructor".

In the C# type system, every class implicitly inherits from System.Object. Therefore, in 99.9% of application code, every class has a base class, and calling base() is valid (referring to System.Object's constructor).

This error only occurs in extremely specific scenarios where you are defining a Root Class, a class that sits at the very top of the inheritance hierarchy and has no parent whatsoever. This is impossible in a standard .NET application because System.Object is always the root. You will typically only encounter this if you are configuring your project to ignore the standard libraries (NoStdLib) to build your own custom runtime or core framework.

Understanding the Class Hierarchy

In a normal C# program:

  1. class MyClass implicitly means class MyClass : System.Object.
  2. public MyClass() : base() implies calling System.Object().

The only class that does not inherit from anything is System.Object itself.

  • If you tried to compile the source code for System.Object, and you wrote : base() in its constructor, you would get CS0517.
  • You cannot look up "the parent of the parent of everyone."

Scenario: Building a Custom Core Library (NoStdLib)

If you have enabled the <NoStdLib>true</NoStdLib> setting in your .csproj file (usually for kernel development, embedded systems, or academic exercises), the compiler stops automatically importing System.Object.

You are now required to define your own base object. When you define this root class, you must not call base().

Example of error

You are defining the root of your custom hierarchy, but you habitually added the base constructor call.

// Project Configuration: <NoStdLib>true</NoStdLib>

namespace System
{
    // This is the root of the hierarchy for this custom environment
    public class Object
    {
        // ⛔️ Error CS0517: 'Object' has no base class and cannot call a base constructor.
        // There is nothing above 'Object'.
        public Object() : base() 
        {
        }
    }
}

Solution: Remove the Base Call

The root class constructor stands alone.

namespace System
{
    public class Object
    {
        // ✅ Correct: No ': base()' call.
        public Object()
        {
            // Root initialization logic
        }
    }
}

Conclusion

CS0517 indicates you have reached the top of the inheritance chain.

  1. Check Project Settings: Unless you are an advanced user building a custom runtime, ensure NoStdLib is disabled in your project properties.
  2. Check the Constructor: If you are indeed writing a root class (like System.Object), delete the : base(...) call from its constructor.
Navigation