Compiler Error CS0106

The modifier 'modifier' is not valid for this item

A class or interface member was marked with an invalid access modifier. The following examples describe some of these invalid modifiers:

  • The static and public modifiers are not permitted on interface methods.

  • The public keyword is not allowed on an explicit interface declaration. In this case, remove the public keyword from the explicit interface declaration.

  • The abstract keyword is not allowed on an explicit interface declaration because an explicit interface implementation can never be overridden.

In prior releases of Visual Studio, the static modifier was not permitted on a class, but static classes are allowed starting with Microsoft Visual Studio 2005.

For more information, see Interfaces (C# Programming Guide)

Example

The following sample generates CS0106.

// CS0106.cs
namespace MyNamespace
{
   interface I
   {
      void m();
      static public void f();   // CS0106
   }

   public class MyClass
   {
      public void I.m() {}   // CS0106
      public static void Main() {}
   }
}