How to Resolve Error "CS0277: Member does not implement interface member because it is not public" in C#
The Compiler Error CS0277 is an interface implementation error. The message reads: " 'Class.Member' does not implement interface member 'Interface.Member'. 'Class.Member' is not public."
In C#, an Interface defines a public contract. When a class promises to implement an interface, the members fulfilling that contract must be accessible to anyone who holds a reference to the interface. Therefore, when implementing an interface implicitly (the standard way), the implementing members in the class must be marked public. If they are private, protected, or internal, the compiler raises CS0277.
This guide explains the visibility rules of interface implementations and how to resolve access conflicts.
Understanding Interface Contracts
When you define an interface:
public interface ILogger
{
void Log(string message);
}
You are stating that any object implementing ILogger must have a method named Log that the outside world can call.
If you implement this in a class, but keep the method private, the class technically "has" the method, but the outside world cannot reach it. This breaks the interface's promise of availability.
Scenario 1: Default Private Visibility
The most common cause is forgetting to add an access modifier. In C# classes, members are private by default if no modifier is specified.
Example of error:
public interface ISaveable
{
void Save();
}
public class Document : ISaveable
{
// ⛔️ Error CS0277: 'Document.Save()' does not implement 'ISaveable.Save()'.
// 'Document.Save()' is not public.
// Explanation: Missing modifier == private.
void Save()
{
System.Console.WriteLine("Saved.");
}
}
Scenario 2: Protected or Internal Access
Sometimes developers try to restrict the interface implementation to derived classes (protected) or the current assembly (internal). Standard implicit implementation does not support this; the method must be fully public.
Example of error:
public interface IProcess
{
void Execute();
}
public class Worker : IProcess
{
// ⛔️ Error CS0277: 'protected' is not accessible enough.
protected void Execute()
{
// ...
}
}
Solution 1: Make the Member Public (Standard Fix)
If you are implementing the interface implicitly (so that obj.Method() works on the class instance directly), you must explicitly add the public keyword.
Solution:
public interface ISaveable
{
void Save();
}
public class Document : ISaveable
{
// ✅ Correct: The member is now public, satisfying the interface.
public void Save()
{
System.Console.WriteLine("Saved.");
}
}
Solution 2: Use Explicit Interface Implementation
If you do not want the method to be part of the class's public API (for example, you want to hide Save() from Document instances but allow it when cast to ISaveable), you should use Explicit Interface Implementation.
Explicit members do not use access modifiers (no public, no private). They are effectively private to the class but accessible via the interface.
Solution: remove the access modifier and prefix the method name with the interface name.
public interface IProcess
{
void Execute();
}
public class Worker : IProcess
{
// ✅ Correct: Explicit implementation.
// Note: No 'public' keyword is allowed here.
void IProcess.Execute()
{
System.Console.WriteLine("Executing...");
}
}
public class Program
{
static void Main()
{
Worker w = new Worker();
// w.Execute(); // Error: Not accessible on 'Worker'
// Allowed when cast to interface
((IProcess)w).Execute();
}
}
Use Explicit Implementation to resolve naming conflicts or to "hide" advanced/internal members from the class's main public interface to keep the API clean.
Conclusion
CS0277 enforces the public nature of interfaces.
- Check Modifiers: Did you forget to type
public? (Remember, class members default toprivate). - Standard Fix: Add
publicto the method or property signature. - Alternative: If you intended to hide the member, switch to Explicit Implementation (
void IInterface.Method()).