Skip to main content

How to Resolve Error "CS0644: 'MyClass' cannot derive from special class 'System.ValueType' (or Enum, Delegate, Array)" in C#

The Compiler Error CS0644 is an inheritance restriction error. The message reads: "'MyClass' cannot derive from special class 'System.ValueType' (or Enum, Delegate, Array)".

In .NET, certain classes in the System namespace are considered Special Classes. These classes (System.ValueType, System.Enum, System.Delegate, System.Array) provide the underlying functionality for fundamental language features. The C# language exposes these features through specific keywords (struct, enum, delegate). You are not allowed to inherit from these base classes explicitly; you must use the corresponding language keyword instead.

This guide explains which classes are restricted and the correct syntax to create those types.

Understanding Special Classes

The Common Language Runtime (CLR) treats specific classes as "Templates" or "Base definitions" for internal mechanisms. C# forbids explicit inheritance from them because the compiler needs to generate specific IL code structure that manual inheritance would violate.

The Restricted List:

  • System.ValueType: The base for all value types.
  • System.Enum: The base for all enumerations.
  • System.Delegate and System.MulticastDelegate: The base for function pointers.
  • System.Array: The base for arrays.

Scenario 1: Inheriting from System.ValueType

If you want to create a Value Type (a lightweight object stored on the stack), you might think you should inherit from System.ValueType. This triggers CS0644.

Example of error

// ⛔️ Error CS0644: 'MyPoint' cannot derive from special class 'ValueType'
public class MyPoint : System.ValueType
{
public int X;
public int Y;
}

Solution: Use struct

In C#, the struct keyword automatically tells the compiler to inherit from System.ValueType behind the scenes.

// ✅ Correct: Using 'struct' creates a Value Type
public struct MyPoint
{
public int X;
public int Y;
}

Scenario 2: Inheriting from System.Enum

Similarly, you cannot define a class that inherits from System.Enum. Enums require special compile-time constant handling and storage field generation that a standard class definition does not provide.

Example of error

// ⛔️ Error CS0644: 'Status' cannot derive from special class 'Enum'
public class Status : System.Enum
{
public static int Active = 1;
}

Solution: Use enum

Use the enum keyword.

// ✅ Correct: Defines an enumeration
public enum Status
{
Active = 1,
Inactive = 0
}

Scenario 3: Inheriting from System.Delegate

Delegates are types-safe function pointers. The compiler generates an Invoke method with a signature matching your definition. You cannot manually inherit from System.Delegate to create one.

Example of error

// ⛔️ Error CS0644: 'MyCallback' cannot derive from special class 'Delegate'
public class MyCallback : System.Delegate
{
}

Solution: Use delegate

Use the delegate keyword to define the signature.

// ✅ Correct: Defines a delegate type
public delegate void MyCallback(string message);

Conclusion

CS0644 implies you are trying to do manually what the C# compiler wants to do for you automatically.

  1. If inheriting ValueType: Use struct.
  2. If inheriting Enum: Use enum.
  3. If inheriting Delegate: Use delegate.