Skip to main content

How to Resolve Error "CS0516: Constructor 'constructor' cannot call itself" in C#

The Compiler Error CS0516 is a recursion error. The message reads: "Constructor 'ClassName.ClassName()' cannot call itself".

In C#, constructors can call other constructors in the same class using the : this(...) syntax to reduce code duplication. However, the compiler performs a dependency check to ensure this chain does not form an infinite loop. If a constructor calls itself directly, or if a chain of constructors eventually loops back to the start (Circular Dependency), the compiler raises CS0516 because creating an instance of the class would be impossible—it would run infinitely until a Stack Overflow occurred.

This guide explains how to identify and fix these recursive constructor chains.

Understanding Constructor Chaining

Constructor chaining allows you to pass default values from a specific constructor to a more general one.

  • Valid: public User() : this("DefaultName") { } calls public User(string name).
  • Invalid: public User() : this() { } calls itself.

The flow must always be acyclic (it must eventually reach a constructor that does not call this(...), usually one that calls base(...) or nothing).

Scenario 1: Direct Recursion (Calling Itself)

This is the simplest form of the error. A constructor explicitly calls its own signature via this.

Example of error

public class User
{
public string Name { get; set; }

// ⛔️ Error CS0516: Constructor 'User.User()' cannot call itself.
// Calling 'this()' invokes the exact same constructor again, creating an infinite loop.
public User() : this()
{
Name = "Default";
}
}

Solution: Remove or Redirect

If this is the default constructor, simply remove the : this() call.

public class User
{
public string Name { get; set; }

// ✅ Correct: No chaining needed. It runs its own body directly.
public User()
{
Name = "Default";
}
}

Scenario 2: Indirect/Circular Recursion

This occurs when you have multiple constructors that call each other in a circle. Constructor A calls Constructor B, and Constructor B calls Constructor A.

Example of error

public class Point
{
public int X { get; set; }
public int Y { get; set; }

// Constructor A calls B
public Point() : this(0)
{
}

// Constructor B calls A
// ⛔️ Error CS0516: Circular dependency detected.
public Point(int x) : this()
{
X = x;
}
}

Solution: Designate a "Master" Constructor

To fix circular dependencies, pick one constructor to contain the core logic (the Master Constructor). All other constructors should feed into that one. The Master Constructor should typically be the one with the most parameters.

public class Point
{
public int X { get; set; }
public int Y { get; set; }

// 1. Convenience Constructor: Calls Master with defaults
public Point() : this(0, 0)
{
}

// 2. Convenience Constructor: Calls Master with partial defaults
public Point(int x) : this(x, 0)
{
}

// 3. Master Constructor: Does the actual work.
// It does NOT call 'this(...)'. It might call 'base(...)' implicitly.
// ✅ Correct: Breaks the cycle.
public Point(int x, int y)
{
X = x;
Y = y;
}
}

Conclusion

CS0516 prevents your application from crashing with a StackOverflowException during object creation.

  1. Check this(...): Look at what is inside the parentheses.
  2. Trace the Path: Follow the calls. Does A go to B? Does B go back to A?
  3. Use a Funnel: Design your class so that simple constructors pass data to complex constructors, ending in one "Master" constructor that initializes the fields.