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 modifier is not permitted on a local function. The static local function feature is supported starting with C# 8.0. A compiler that doesn't support C# 8.0 produces CS0106 when you try to use this feature. However, a compiler that supports C# 8.0 but the set language version is prior to C# 8.0 will produce a diagnostic suggesting that you use C# 8.0 or later.

  • 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.

  • Access modifiers are not allowed on a local function. Local functions are always private.

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

For more information, see Interfaces.


The following sample generates CS0106:

// CS0106.cs
namespace MyNamespace
   interface I
      void M();

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