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;
}
}
Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide.
.NET feedback
The .NET documentation is open source. Provide feedback here.
Feedback
Submit and view feedback for