C# Compiler Error
CS0507 – ‘function1’ : cannot change access modifiers when overriding ‘access’ inherited member ‘function2’
Reason for the Error
You’ll get this error in your C# code when you attempt to change the access modifier in the method override.
For example, let’s try to compile the below C# code snippet.
using System; namespace DeveloperPublishNamespace { abstract public class BaseClass { virtual protected void Method1() { } } public class ChildClass : BaseClass { public override void Method1() { } } class Program { static void Main(string[] args) { Console.WriteLine("No Error"); } } }
using System;
namespace DeveloperPublishNamespace
{
abstract public class BaseClass
{
virtual protected void Method1()
{
}
}
public class ChildClass : BaseClass
{
public override void Method1()
{
}
}
class Program
{
static void Main(string[] args)
{
Console.WriteLine("No Error");
}
}
}
You’ll receive the error code CS0507 because the C# compiler has detected that you are overriding the function “Method1” but changing the access modifier to public when overriding.
Error CS0507 ‘ChildClass.Method1()’: cannot change access modifiers when overriding ‘protected’ inherited member ‘BaseClass.Method1()’ DeveloperPublish C:\Users\Senthil\source\repos\ConsoleApp4\ConsoleApp4\Program.cs 13 Active

Solution
You can fix this error in your C# program by making sure that the access modifiers remain the same when overriding the inherited member.
using System; namespace DeveloperPublishNamespace { abstract public class BaseClass { virtual protected void Method1() { } } public class ChildClass : BaseClass { protected override void Method1() { } } class Program { static void Main(string[] args) { Console.WriteLine("No Error"); } } }
xxxxxxxxxx
using System;
namespace DeveloperPublishNamespace
{
abstract public class BaseClass
{
virtual protected void Method1()
{
}
}
public class ChildClass : BaseClass
{
protected override void Method1()
{
}
}
class Program
{
static void Main(string[] args)
{
Console.WriteLine("No Error");
}
}
}
Related

C# Error CS0506 – ‘function1’ : cannot override inherited member ‘function2’ because it is not marked “virtual”, “abstract”, or “override”
C# Compiler Error CS0506 – 'function1' : cannot override inherited member 'function2' because it is not marked "virtual", "abstract", or "override" Reason for the Error You'll get this error in your C# code when you attempt to override a member that is not explicitly marked as virtual, abstract, or override…
In "CSharp"

C# Error CS0534 – ‘function1’ does not implement inherited abstract member ‘function2’
C# Compiler Error CS0534 – 'function1' does not implement inherited abstract member 'function2' Reason for the Error You’ll get this error in your C# code when you have not implemented all the abstract members of the base class especially when the inherited class is not an abstract class. For example,…
In "CSharp"

C# Error CS0112 – A static member ‘function’ cannot be marked as override, virtual or abstract
C# Compiler Error CS0112 – A static member 'function' cannot be marked as override, virtual or abstract Reason for the Error You will receive this error when you use the static keyword along with any of these keywords for the function definition. overridevirtualabstract For example, the below code snippet demonstrates…
In "CSharp"