Compiler Error CS0507

 

Updated: July 20, 2015

System_CAPS_ICON_note.jpg Note

For the latest documentation on C#, visit the C# Guide on docs.microsoft.com.

'function1' : cannot change access modifiers when overriding 'access' inherited member 'function2'

An attempt was made to change the access specification in a method override.

The following sample generates CS0507.

// CS0507.cs  
abstract public class clx  
{  
   virtual protected void f() {}  
}  
  
public class cly : clx  
{  
   public override void f() {}   // CS0507  
   public static void Main() {}  
}  

CS0507 can also occur if a class attempts to override a method marked as protected internal defined in referenced metadata. In this situation, the overriding method should be marked as protected.

// CS0507_b.cs  
// compile with: /target:library  
abstract public class clx  
{  
   virtual protected internal void f() {}  
}  

The following sample generates CS0507.

// CS0507_c.cs  
// compile with: /reference:cs0507_b.dll  
public class cly : clx  
{  
   protected internal override void f() {}   // CS0507  
   // try the following line instead  
   // protected override void f() {}   // OK  
  
   public static void Main() {}  
}  

Show: