How to Resolve Error "CS0737: Member does not implement interface member because it is not public" in C#
The Compiler Error CS0737 is a visibility mismatch error. The message reads: "'ClassMember' does not implement interface member 'InterfaceMember'. It cannot implement an interface member because it is not public."
In C#, an Interface represents a public contract. It defines a set of behaviors that must be accessible to anyone holding a reference to that interface. Therefore, when you implement an interface in a class using Implicit Implementation (the standard way), the implementing method or property must be marked public. If you make it internal, protected, or private (or leave it as default private), it fails to fulfill the public promise of the interface.
This guide explains how to fix this by adjusting access modifiers or using Explicit Interface Implementation.
Understanding Interface Contracts
When Class A implements Interface I, it promises that every member defined in I exists on A.
Since interfaces are generally used to expose functionality to outside callers, the implementing members on the class must be public.
- Allowed:
public void Method() - Forbidden (CS0737):
internal void Method(),protected void Method(),void Method()(Default Private).
Scenario 1: Default or Restricted Access Modifiers
This is the most common cause. You declare a class that implements an interface, but you forget to add the public keyword to the methods. In C#, class members are private by default.
Example of error
public interface ILogger
{
void Log(string message);
}
public class FileLogger : ILogger
{
// ⛔️ Error CS0737: 'FileLogger.Log(string)' does not implement interface member.
// It cannot implement the interface member because it is not public.
// (Missing access modifier = private)
void Log(string message)
{
System.Console.WriteLine(message);
}
}
Solution: Add public
To satisfy implicit implementation, simply make the member public.
public class FileLogger : ILogger
{
// ✅ Correct: The member is now public, satisfying the interface contract.
public void Log(string message)
{
System.Console.WriteLine(message);
}
}
Even if the interface itself is marked internal, the implementing method on the class must still be public if you are using implicit implementation.
Scenario 2: Hiding Members (Explicit Implementation)
Sometimes, you do not want the method to be public on the class itself. Perhaps it is an internal utility, or the name conflicts with another method, or you simply want to hide it from the class's public API while still satisfying the interface.
You cannot use protected or internal to solve this (that triggers CS0737). Instead, you must use Explicit Interface Implementation.
Example of error
Trying to use protected to hide the implementation details.
public interface IEngine
{
void Start();
}
public class Car : IEngine
{
// ⛔️ Error CS0737: You cannot use 'protected' to implement an interface member.
protected void Start()
{
// ...
}
}
Solution: Use Explicit Implementation
Remove the access modifier entirely and prefix the method name with the interface name.
public class Car : IEngine
{
// ✅ Correct: Explicit implementation.
// 1. No access modifier (implicitly public ONLY via the interface).
// 2. Prefixed with 'IEngine.'.
void IEngine.Start()
{
Console.WriteLine("Car started");
}
// You can now have your own internal logic if needed
private void InternalStartLogic() { /*...*/ }
}
public class Program
{
static void Main()
{
Car c = new Car();
// c.Start(); // Error: Not accessible on the class directly
// Accessible via the interface
((IEngine)c).Start();
}
}
Conclusion
CS0737 ensures that the "Public Contract" of an interface is honored.
- Check Modifiers: Did you forget the
publickeyword? - Implicit vs. Explicit:
- If you want the method visible on the class: Add
public. - If you want the method hidden (or "protected" from direct class access): Use Explicit Implementation (
void IInterface.Method()).
- If you want the method visible on the class: Add