How to Resolve Error "CS0522: structs cannot call base class constructors" in C#
The Compiler Error CS0522 is a syntax restriction related to Value Types. The message reads: "Structs cannot call base class constructors".
In C#, a struct is a value type. While all structs implicitly inherit from System.ValueType (which in turn inherits from System.Object), C# does not support user-defined inheritance for structs. You cannot define a struct that inherits from a class or another struct. Because there is no "parent class" logic that you are allowed to invoke or modify, the compiler forbids the use of the : base(...) syntax in struct constructors.
This guide explains the limitations of struct inheritance and how to correctly initialize them.
Understanding Struct Inheritance
Classes support inheritance: class Child : Parent. When constructing a Child, you often need to ensure Parent is initialized, so you call base().
Structs are different:
- They are sealed. You cannot inherit from them.
- They cannot inherit from other types (except interfaces).
- Their inheritance from
System.ValueTypeis handled implicitly and automatically by the runtime.
Since you cannot define a base class for your struct, calling base() is trying to call a constructor that is logically inaccessible to you.
Scenario: The Invalid Constructor Chain
This error often occurs when developers apply habits from Class-based Object Oriented Programming to Structs, assuming they need to call the object constructor.
Example of error:
public struct Point
{
public int X;
public int Y;
// ⛔️ Error CS0522: structs cannot call base class constructors.
// Even though Point technically inherits from System.ValueType -> System.Object,
// C# forbids explicit calls to base() for structs.
public Point(int x, int y) : base()
{
X = x;
Y = y;
}
}
Solution: Remove the Base Call
To fix this, simply remove the : base() part. Structs are initialized to zero/null by default before the constructor body runs; there is no parent initialization logic required.
Solution:
public struct Point
{
public int X;
public int Y;
// ✅ Correct: No call to base().
// You can still call other constructors in the SAME struct using 'this()'.
public Point(int x, int y)
{
X = x;
Y = y;
}
}
Constructor Chaining (this):
While base() is forbidden, chaining to other constructors within the same struct using : this(...) is perfectly valid and useful for setting default values.
Conclusion
CS0522 reminds you that Structs are not Classes.
- No Inheritance: Structs do not participate in class hierarchies.
- No Base: There is no base constructor for you to invoke.
- The Fix: Delete
: base()from your struct constructor declaration.