How to Resolve Error "CS0550: Member adds an accessor not found in interface member" in C#
The Compiler Error CS0550 is an interface compliance error regarding Explicit Interface Implementation. The message reads: "'Class.Member' adds an accessor not found in interface member 'Interface.Member'".
In C#, when you implement an interface explicitly (by prefixing the member name with the interface name, like int IMyInterface.Prop), you are strictly fulfilling the contract defined by that interface. You cannot add extra capabilities to that specific implementation. If the interface defines a property as Read-Only (get), you cannot explicitly implement a setter (set) for it, because that setter does not exist in the interface's definition.
This guide explains strict interface matching and how to handle properties that need extra accessors.
Understanding Explicit Implementation Rules
When you implement an interface implicitly (using public), you are allowed to add extra accessors because the member belongs to the class and satisfies the interface.
- Implicit:
public int Prop { get; set; }satisfiesinterface { int Prop { get; } }. Thesetis just extra class functionality.
However, when you implement it explicitly, the member belongs only to the interface view.
- Explicit:
int IInterface.Prop { get; set; }fails againstinterface { int Prop { get; } }. The compiler looks at the interface, sees no setter, and rejects the implementation becauseIInterface.Prop.setis not a valid method signature in the contract.
Scenario 1: Adding a set to a Read-Only Interface
This is the most common cause. The interface defines a value that can be read, but your implementation tries to define how it is written as part of the explicit implementation.
Example of error
public interface IConfig
{
// Interface says: Read-Only
int Timeout { get; }
}
public class AppConfig : IConfig
{
// ⛔️ Error CS0550: 'AppConfig.IConfig.Timeout' adds an accessor not found in interface member 'IConfig.Timeout'.
// You cannot add 'set' here because IConfig doesn't have a setter.
int IConfig.Timeout
{
get { return 1000; }
set { }
}
}
Solution: Remove the Extra Accessor
If you are implementing the interface explicitly, you must match the accessors exactly.
public class AppConfig : IConfig
{
private int _timeout = 1000;
// ✅ Correct: Only implements 'get', matching the interface.
int IConfig.Timeout
{
get { return _timeout; }
}
// If you need to set it, create a separate member on the class
public void SetTimeout(int val)
{
_timeout = val;
}
}
Alternative Solution: Use Implicit Implementation
If you want the property to have a setter that is visible on the class itself, do not use explicit implementation.
public class AppConfig : IConfig
{
// ✅ Correct: Implicit implementation.
// The 'get' satisfies the interface. The 'set' is valid for the class.
public int Timeout { get; set; }
}
Scenario 2: Adding a get to a Write-Only Interface
Less common, but applies to the reverse situation. If an interface is designed for output only (like a log sink), you cannot explicitly add a getter.
Example of error
public interface ILogger
{
// Interface says: Write-Only
string LogMessage { set; }
}
public class ConsoleLogger : ILogger
{
// ⛔️ Error CS0550: You cannot add 'get' to this explicit implementation.
string ILogger.LogMessage
{
get { return "Unknown"; }
set { System.Console.WriteLine(value); }
}
}
Solution: Match the Interface
Remove the get accessor from the explicit declaration.
public class ConsoleLogger : ILogger
{
// ✅ Correct: Matches Write-Only contract.
string ILogger.LogMessage
{
set { System.Console.WriteLine(value); }
}
}
If you need to read the value internally, store it in a private field and access that field directly, rather than trying to add a getter to the interface implementation.
Conclusion
CS0550 enforces strict adherence to the interface contract when using explicit syntax.
- Check the Interface: Does
IInterfacedefine bothgetandset? - Check the Implementation: Does your
Type IInterface.Memberinclude extra accessors? - The Fix: Remove the extra accessor from the explicit implementation. If you need that functionality, implement it as a separate public member or use implicit implementation.