How to Resolve Error "CS0713: Static class cannot derive from type. Static classes must derive from object." in C#
The Compiler Error CS0713 is an inheritance restriction error. The message reads: "Static class 'StaticType' cannot derive from type 'BaseType'. Static classes must derive from object."
In C#, a static class is designed to be a container for global utility methods and data (like System.Math). It cannot be instantiated (new), and it is implicitly sealed. Inheritance implies an "is-a" relationship between objects (e.g., "Dog is an Animal"), where the child inherits instance fields and virtual methods. Since a static class has no instance, it cannot inherit state or behavior from another class.
This guide explains how to restructure your code to achieve code reuse without invalid inheritance.
Understanding Static Class Inheritance
All classes in C# inherit from System.Object.
- Standard Class: Can inherit from other classes to gain their properties and methods.
- Static Class: Is structurally forbidden from inheriting from anything other than
System.Object.
If you try to write static class MyUtils : List<int>, the compiler blocks it. List<int> defines instance methods (Add, Remove) that work on a specific list object. A static class cannot "be" a list because it cannot hold the instance state required to make the list work.
Scenario: Attempting to Extend a Class Statically
This error often occurs when developers want to group global settings but try to inherit default settings from a base class, or when they try to create a "Global List" by inheriting from List<T>.
Example of error:
public class BaseConfig
{
public int DefaultTimeout = 30;
}
// ⛔️ Error CS0713: Static class 'AppConfig' cannot derive from type 'BaseConfig'.
// Static classes must derive from object.
public static class AppConfig : BaseConfig
{
public static string AppName = "MyApp";
}
Solution 1: Use Composition (Delegation)
Instead of the static class inheriting from the base class ("Is-A"), the static class should contain an instance of the base class ("Has-A"). This is known as Composition.
Solution: declare a static field that holds the object you wanted to inherit from.
public class BaseConfig
{
public int DefaultTimeout = 30;
}
public static class AppConfig
{
// ✅ Correct: We contain a BaseConfig instance instead of inheriting from it.
private static BaseConfig _settings = new BaseConfig();
public static string AppName = "MyApp";
// We expose the functionality via a static property
public static int Timeout => _settings.DefaultTimeout;
}
Solution 2: Use Extension Methods
If your goal was to add new methods to an existing class (like adding a helper method to string or List<T>), you shouldn't create a static class that inherits from them. Instead, you should create a static class that defines Extension Methods.
Example of error
// ⛔️ Error CS0713: You cannot inherit from String to add methods to it.
public static class MyStringExtensions : String
{
}
Solution
Use the this keyword in the parameter list.
// ✅ Correct: A standard static class used for extensions.
public static class StringExtensions
{
// This adds a .WordCount() method to ANY string object.
public static int WordCount(this string str)
{
return str.Split(' ').Length;
}
}
Solution 3: Make the Class Non-Static
If you genuinely need inheritance—for example, you want to override virtual methods or use polymorphism (passing the object to a method that expects the Base Class)—then your class cannot be static.
Solution: remove the static keyword. You can still use the Singleton Pattern if you only want one instance of it to exist.
public class BaseConfig
{
public virtual void Load() { Console.WriteLine("Base Load"); }
}
// ✅ Correct: Removed 'static'. Now supports inheritance.
public class AppConfig : BaseConfig
{
// Singleton instance (optional, if you want global access behavior)
public static readonly AppConfig Instance = new AppConfig();
private AppConfig() { } // Private constructor
public override void Load()
{
Console.WriteLine("AppConfig Load");
}
}
Conclusion
CS0713 enforces the definition of a static class as a standalone utility container.
- Composition: If you want to use logic from another class, create a
private staticinstance of that class inside your static class. - Extensions: If you want to add methods to a class, use Extension Methods (
this Type name). - Inheritance: If you strictly need inheritance, remove the
statickeyword and use the Singleton pattern if "global" access is required.