Compiler Error CS0122

'member' is inaccessible due to its protection level

The access modifier for a class member prevents accessing the member. For more information, see Access Modifiers.

One cause of this (not shown in the sample below) can be omitting the /out compiler flag on the target of a friend assembly. For more information, see Friend Assemblies and OutputAssembly (C# Compiler Options).

Example

The following sample generates CS0122:

// CS0122.cs
public class MyClass
{
    // Make public to resolve CS0122.
    void MyMethod()
    {
    }
}

public class MyClass2
{
    public static int Main()
    {  
        var a = new MyClass();  
        // MyMethod is private.
        a.MyMethod();   // CS0122
        return 0;
   }
}