Export (0) Print
Expand All
Expand Minimize

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 (C# Programming Guide).

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 (C# and Visual Basic) and /out (C# Compiler Options)

The following sample generates CS0122:

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

public class MyClass2
    public static int Main()
        MyClass a = new MyClass();
        // MyMethod is private
        a.MyMethod();   // CS0122
        return 0;
© 2015 Microsoft