How to Resolve Error "CS0535: 'class' does not implement interface member 'member'" in C#
The Compiler Error CS0535 is an interface compliance error. The message reads: "'ClassName' does not implement interface member 'InterfaceName.MemberName'".
In C#, an Interface is a strict contract. If a class claims to implement an interface (e.g., class MyClass : IMyInterface), it must provide a public implementation for every single method, property, event, or indexer defined in that interface. If even one member is missing, or if the implementation is not public, the compiler raises CS0535.
This guide explains how to fulfill these contracts correctly.
Understanding Interface Implementation
When you write class User : IUser, you are signing a binding agreement.
- The Contract:
IUsersays "You must have a methodvoid Save()." - The Fulfillment:
Usermust have a methodpublic void Save() { ... }.
The implementation must match the interface member's name, return type, and parameters exactly. Furthermore, implicit implementations must always be public.
Scenario 1: Missing Implementation
The most straightforward cause is simply forgetting to write the method. You added the interface to the class declaration line but haven't written the code yet.
Example of error
public interface ILogger
{
void Log(string message);
}
// ⛔️ Error CS0535: 'FileLogger' does not implement interface member 'ILogger.Log(string)'
public class FileLogger : ILogger
{
// The class body is empty. The method 'Log' is missing.
}
Solution: Implement the Member
Add the missing method with the exact signature required.
public class FileLogger : ILogger
{
// ✅ Correct: The method exists and matches the signature.
public void Log(string message)
{
Console.WriteLine(message);
}
}
Visual Studio Shortcut:
Click on the interface name (ILogger), press Ctrl + . (or click the lightbulb), and select "Implement interface". The IDE will generate the method stubs for you automatically.
Scenario 2: Missing public Modifier
This is a very common trap. In an interface, members don't have access modifiers (they are implicitly public). In a class, members are private by default. If you write the method but forget to type public, the compiler cannot see it as an implementation of the public interface.
Example of error
public interface ICalculator
{
int Add(int a, int b);
}
public class Calculator : ICalculator
{
// ⛔️ Error CS0535: 'Calculator' does not implement...
// The method exists, but it is implicitly 'private'.
// Interface implementations MUST be public.
int Add(int a, int b)
{
return a + b;
}
}
Solution: Make it Public
Add the public keyword explicitly.
public class Calculator : ICalculator
{
// ✅ Correct: Explicitly public
public int Add(int a, int b)
{
return a + b;
}
}
Explicit Interface Implementation:
Alternatively, you can implement the member explicitly: int ICalculator.Add(int a, int b) { ... }. In this specific case, you do not use public, but the method is also not accessible via the class instance directly (only via the interface).
Scenario 3: Signature Mismatch
You might have written a method that looks similar, but differs slightly in return type or parameters. The compiler considers this a different method, leaving the interface requirement unfulfilled.
Example of error
public interface ISaver
{
void Save(string data);
}
public class DiskSaver : ISaver
{
// ⛔️ Error CS0535: The interface requires 'void Save(string)'.
// We provided 'bool Save(string)'.
// The return types do not match.
public bool Save(string data)
{
return true;
}
}
Solution: Match the Signature
Ensure the return type and parameter types match exactly.
public class DiskSaver : ISaver
{
// ✅ Correct: Matches 'void' return type.
public void Save(string data)
{
// Implementation...
}
}
Conclusion
CS0535 is a contract violation message.
- Check the List: Use your IDE's "Implement Interface" feature to ensure no members are missing.
- Check Visibility: Ensure all implicit implementations are marked
public. - Check Spelling: Ensure parameter types and return types match the interface definition exactly.