How to Resolve Error "CS0115: 'function' : no suitable method found to override" in C#
The Compiler Error CS0115 is an inheritance signature error. The message reads: " 'MyClass.Method': no suitable method found to override".
In C#, the override keyword is a specific instruction to the compiler: "Find a method in the parent class with this exact signature that is marked as virtual, abstract, or override, and replace it with my new version."
If the compiler cannot find a parent method that matches your definition perfectly (name, parameters, and return type) or if the parent method exists but is not marked to allow overriding, it throws CS0115.
This guide explains the strict rules of overriding and how to fix mismatch issues.
Understanding the Override Requirements
To successfully override a method, four conditions must be met:
- Name: Must match exactly (Case-sensitive).
- Parameters: Must match exactly in count, type, and order.
- Return Type: Must match exactly.
- Base Modifier: The parent method must be marked
virtual,abstract, oroverride.
If any of these conditions fails, the compiler assumes you made a mistake and reports that no suitable method exists.
Scenario 1: Signature Mismatch (Typos and Parameters)
This is the most frequent cause. You think you are overriding OnPaint(PaintEventArgs e), but you typed Onpaint or forgot the parameter.
Example of error
public class BaseClass
{
public virtual void SaveData(string path)
{
/* ... */
}
}
public class ChildClass : BaseClass
{
// ⛔️ Error CS0115: no suitable method found to override
// Cause 1: Typo in name ('Savedata' vs 'SaveData')
// Cause 2: Missing parameter (Base requires a string argument)
public override void Savedata()
{
/* ... */
}
}
Solution: Match Exact Signature
Copy and paste the signature from the base class to ensure accuracy, or let your IDE generate the override stub for you.
public class ChildClass : BaseClass
{
// ✅ Correct: Name, Return Type, and Parameters match perfectly.
public override void SaveData(string path)
{
System.Console.WriteLine($"Saving to {path}");
}
}
Scenario 2: Missing 'virtual' in Base Class
You cannot override a standard method. If the parent class has a method, but the author of that class did not mark it as virtual (or abstract), you are not allowed to override it.
Example of error
public class Parent
{
// Standard method. Not overridable.
public void SayHello() { }
}
public class Child : Parent
{
// ⛔️ Error CS0115: 'Child.SayHello()': no suitable method found to override.
// The compiler finds 'SayHello', but it isn't marked 'virtual'.
public override void SayHello() { }
}
Solution: Update Base or Use 'new'
Option A: Allow Overriding
If you own the code for the base class, add the virtual keyword.
public class Parent
{
// ✅ Correct: Marked virtual
public virtual void SayHello() { }
}
public class Child : Parent
{
public override void SayHello() { }
}
Option B: Shadowing
If you cannot change the base class (e.g., it comes from a library), you cannot use override. You must use new to hide the method instead (Shadowing).
public class Child : Parent
{
// ✅ Correct: "I am forcing a new definition of SayHello"
public new void SayHello() { }
}
Scenario 3: Accessibility Mismatch
When overriding a method, the Access Level (public, protected, internal) must match exactly. You cannot make a protected method public in the child, nor vice versa.
Example of error
public class Engine
{
// Defined as protected
protected virtual void Start() { }
}
public class Car : Engine
{
// ⛔️ Error CS0115: (or CS0507 in some versions)
// You cannot change visibility from protected to public.
public override void Start() { }
}
Solution
Match the access modifier defined in the base class.
public class Car : Engine
{
// ✅ Correct: Matches 'protected'
protected override void Start() { }
}
Return Types: The return type must also match exactly. C# supports Covariant Return Types (returning a more specific type) only in C# 9.0+ and .NET 5+. In older versions, even returning a child type instead of a parent type causes CS0115.
Conclusion
CS0115 is the compiler checking your spelling and logic.
- Check Spelling: Is it
ToStringortostring? - Check Parameters: Did you forget an argument or change an
intto adouble? - Check Modifiers: Is the base method actually
virtual? - Check Visibility: Are you accidentally changing
protectedtopublic?