How to Resolve Error "CS0113: A member marked as override cannot be marked as new or virtual" in C#
The Compiler Error CS0113 is a keyword conflict error. The message reads: "A member 'function' marked as override cannot be marked as new or virtual".
In C# inheritance, the keywords override, new, and virtual have specific, often mutually exclusive meanings.
override: Extends or modifies an existing virtual chain.new: Breaks the chain and starts a fresh member with the same name (Shadowing).virtual: Starts a new chain or indicates a member can be overridden.
You cannot combine these. An override member is implicitly virtual, so adding virtual is redundant and invalid. An override member is meant to be part of the existing inheritance chain, so adding new (which breaks the chain) is contradictory.
This guide explains how to correctly configure inheritance modifiers.
Understanding Inheritance Keywords
virtual: "I am the first definition, and I allow children to change me."override: "I am a child, and I am changing the definition provided by my parent." (Note: An overridden method remains virtual for grandchildren automatically).new: "I am a child, but I am ignoring my parent's definition completely. I am a brand new method that just happens to have the same name."
Since override links to the parent, and new unlinks from the parent, you cannot use both simultaneously.
Scenario 1: Combining 'override' and 'new'
This error occurs when a developer is unsure whether they want to replace the method (Polymorphism) or hide it (Shadowing), so they try to use both keywords.
Example of error
public class Parent
{
public virtual void Speak() => Console.WriteLine("Parent speaks");
}
public class Child : Parent
{
// ⛔️ Error CS0113: A member marked as override cannot be marked as new.
// 'override' asks to use the Parent's vtable slot.
// 'new' asks to create a new slot. They conflict.
public override new void Speak()
{
Console.WriteLine("Child speaks");
}
}
Solution: Choose One
Decide on the behavior you want.
Option A: Polymorphism (Override)
Use this if you want Parent p = new Child(); p.Speak(); to output "Child speaks".
public class Child : Parent
{
// ✅ Correct: Extends the parent logic
public override void Speak()
{
Console.WriteLine("Child speaks");
}
}
Option B: Shadowing (New)
Use this if you want Parent p = new Child(); p.Speak(); to output "Parent speaks" (ignoring the child).
public class Child : Parent
{
// ✅ Correct: Hides the parent logic (starts fresh)
public new void Speak()
{
Console.WriteLine("Child speaks");
}
}
Scenario 2: Combining 'override' and 'virtual'
A method marked as override is automatically virtual. This means derived classes (Grandchildren) can override it further. Explicitly adding the virtual keyword to an override method is not allowed because it implies you are starting a new virtual chain, which contradicts the fact that you are continuing an existing one.
Example of error
public class Child : Parent
{
// ⛔️ Error CS0113: A member marked as override cannot be marked as virtual.
// It is ALREADY virtual because it is an override.
public override virtual void Speak()
{
Console.WriteLine("Child speaks");
}
}
Solution: Remove 'virtual'
Simply delete the virtual keyword. The method remains open for further overriding by default.
public class Child : Parent
{
// ✅ Correct: This implies 'virtual' for any class inheriting from Child.
public override void Speak()
{
Console.WriteLine("Child speaks");
}
}
public class GrandChild : Child
{
// This works perfectly fine
public override void Speak() { }
}
Advanced: Stopping Inheritance (Sealed)
Sometimes, developers add new or try to manipulate keywords because they want to stop further subclasses from overriding the method. The correct keyword for this is sealed.
If you want to override the parent but prevent grandchildren from changing it further:
public class Child : Parent
{
// ✅ Correct: Overrides the parent, but locks it for future generations.
public sealed override void Speak()
{
Console.WriteLine("Child speaks (Final)");
}
}
Conclusion
CS0113 is a redundancy and logic check.
- Check Logic: Do you want to inherit (
override) or hide (new)? You cannot do both. - Check Redundancy: Do not add
virtualto anoverride. Overrides are virtual by nature. - Use Sealed: If your goal was to prevent further changes, use
sealed override.