Skip to main content

How to Resolve Error "CS0470: Method cannot implement interface accessor for type" in C#

The Compiler Error CS0470 is a specific error related to Interface Implementation, particularly regarding properties and events. The message reads: "Method 'MyMethod' cannot implement interface accessor 'AccessorName' for type 'InterfaceType'. Use an explicit interface implementation."

In C#, properties and events are actually composed of accessor methods (like get_Prop, set_Prop, add_Event, remove_Event) under the hood. This error occurs when the compiler detects a method in your class that could logically act as one of these accessors, but C# rules forbid mapping a standard public method directly to an interface accessor in this context. The compiler requires you to explicitly tie that method to the interface using Explicit Interface Implementation.

This guide explains how to properly implement interface accessors when custom logic or naming conflicts arise.

Understanding Interface Accessors

When an interface defines an event:

public interface INotify
{
event EventHandler SomethingHappened;
}

It effectively defines two methods: add_SomethingHappened and remove_SomethingHappened.

If you try to implement this interface by simply writing a method named add_SomethingHappened in your class, the C# compiler refuses to map this method to the interface's event accessor. Unlike some languages where naming conventions are enough to satisfy interfaces, C# requires specific syntax (the event keyword or explicit mapping) to link the implementation to the contract.

Scenario: Implementing Events with Custom Accessors

This error is most common when developers try to manually implement the underlying methods of an event instead of using the standard event syntax.

Example of error: trying to satisfy an interface event by declaring raw add_ or remove_ methods.

using System;

public interface IClickable
{
// Requires accessors: add_Click and remove_Click
event EventHandler Click;
}

public class Button : IClickable
{
// ⛔️ Error CS0470: Method 'Button.add_Click(EventHandler)' cannot implement
// interface accessor 'IClickable.Click.add'.
// Use an explicit interface implementation.
public void add_Click(EventHandler value)
{
Console.WriteLine("Subscribed");
}

public void remove_Click(EventHandler value)
{
Console.WriteLine("Unsubscribed");
}
}

The compiler sees that add_Click exists, but it refuses to use a standard method to fulfill the role of the special add accessor required by the interface.

Solution 1: Use Explicit Interface Implementation

As the error message suggests, if you need to define exactly how the add/remove logic works for that specific interface (and perhaps hide it from the public API of the class), use Explicit Interface Implementation.

This involves prefixing the event name with the interface name.

Solution:

using System;

public interface IClickable
{
event EventHandler Click;
}

public class Button : IClickable
{
// A private backing field to store delegates
private EventHandler _click;

// ✅ Correct: Explicit implementation syntax
// Note: No access modifier (public/private) allowed here.
event EventHandler IClickable.Click
{
add
{
Console.WriteLine("Explicit Add");
_click += value;
}
remove
{
Console.WriteLine("Explicit Remove");
_click -= value;
}
}
}

Solution 2: Use Standard Implicit Implementation

If you do not have a specific reason to hide the event or write complex accessor logic, simply use the standard C# syntax for implementing events. This implicitly creates the accessors and maps them to the interface correctly.

Solution: use the public event syntax.

using System;

public interface IClickable
{
event EventHandler Click;
}

public class Button : IClickable
{
// ✅ Correct: Implicit implementation.
// The compiler automatically generates the add/remove accessors
// and maps them to IClickable.Click.
public event EventHandler Click;
}

If you need custom logic (e.g., logging) but want it to be public:

public class Button : IClickable
{
private EventHandler _click;

// ✅ Correct: Custom accessors on a public event
public event EventHandler Click
{
add { _click += value; }
remove { _click -= value; }
}
}

Conclusion

CS0470 enforces the structure of property and event implementation.

  1. Don't use raw methods: Do not try to implement add_EventName or get_PropertyName as simple void methods to satisfy an interface.
  2. Use Event Syntax: Use the event keyword block { add { } remove { } }.
  3. Follow the Recommendation: If the compiler asks for Explicit Interface Implementation, prefix the member name with the interface name (e.g., event EventHandler IMyInterface.MyEvent).