C# Error CS0106 – The modifier ‘modifier’ is not valid for this item

C# Compiler Error

CS0106 – The modifier ‘modifier’ is not valid for this item

Reason for the Error

You will receive this error when you have marked your class or interface with an invalid access modifier.

Take the below code snippet as an example.

abstract interface ITest
{
   public void M();
}

public class DeveloperPublish
{
    public static void Main()
    {

    }
}

You have an interface by the name ITest and you have prefixed it with the abstract keyword in the explicit interface declaration.

This will result in the CS0106 error.

C# Error CS0106 – The modifier 'modifier' is not valid for this item

Solution

To fix the above error, remove the abstract keyword from the explicit interface declaration.

There are plenty of other scenarios where you would encounter a similar scenario. For example, in the C# versions before C# 8.0 and when you have the public keyword defined on the explicit interface declaration, you will receive the same error.

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

C# Compiler Error CS0442 – ‘Property’: abstract properties cannot have private accessors Reason for the Error You’ll get this error...
This is a really simple one . Below is a simple example of an enum called “Designation” defined with the...
This blog post explain the usage of the Checked Block in .NET and how you can use them in Visual...