Ad Space — Top Banner

CS0051

C# Programming Language

Severity: Minor

What Does This Error Mean?

CS0051 means you have inconsistent accessibility — a public method or property uses a type that is less accessible than the method itself. For example, if a public method returns a type that is internal or private, other code that can see the method cannot see the return type. C# requires that all types mentioned in a public member's signature must be at least as accessible as the member itself. The fix is to make the return type public, or reduce the method's accessibility to match the return type.

Affected Models

  • .NET Framework
  • .NET Core
  • .NET 5+
  • All C# versions

Common Causes

  • A public method returns an internal or private class — external code cannot use the return type
  • A public property has a type that is internal — not accessible outside the assembly
  • A public method takes a parameter of an internal type — external callers cannot provide that type
  • A public class inherits from an internal or private class
  • Forgetting to add the 'public' modifier to a class used in a public method signature

How to Fix It

  1. Read the error message — it tells you exactly which method and which type have the accessibility mismatch.

    Example: 'Inconsistent accessibility: return type Test.MyClass is less accessible than method Test.Manager.GetItem()'

  2. If the type should be publicly accessible, add the 'public' modifier to it.

    Change: class MyClass { } to: public class MyClass { } — now it is accessible to all callers.

  3. If the type should stay internal (not publicly visible), reduce the method's accessibility to 'internal' instead of 'public'.

    Change: public MyClass GetItem() to: internal MyClass GetItem() — now both the method and its return type are internal.

  4. Review your design. If a public method needs to return an internal type, consider whether that type should actually be public (it is part of your API), or whether the method should be internal.

    API design rule: if something is part of your public interface, everything it touches should also be public.

  5. Check interfaces and base classes too. If a public interface or public class uses an internal type anywhere in its definition, you will get CS0051 there as well.

    Accessibility must be consistent throughout the chain — public class, public method, public return type, public parameter types.

When to Call a Professional

CS0051 is a compile-time error that you can always fix yourself. Decide whether the type should be public, or whether the method that uses it should be less accessible. The fix is usually to add 'public' to the type, or to change the method to 'internal'.

Frequently Asked Questions

What do public, internal, private, and protected mean in C#?

public: accessible from anywhere. internal: accessible only within the same assembly (.dll or .exe). private: accessible only within the same class. protected: accessible within the class and derived (child) classes. For accessibility rules, public is the most visible and private is the least.

What is an assembly in C#?

An assembly is the compiled output of a C# project — a .dll or .exe file. Internal types are visible within the same assembly but not from other assemblies. If you have a library project and an app project, the app project is a separate assembly — it cannot see internal types in the library.

Why does C# enforce consistent accessibility?

Because otherwise you would have unreachable types. If a public method returns an internal type, external callers can call the method but cannot use the value it returns — they do not have access to the type. C# catches this at compile time to prevent confusing and unusable API designs.