Skip to main content

How to Resolve Error "CS1055: An add or remove accessor expected" in C#

The Compiler Error CS1055 is a syntax error related to Event Declarations. The message reads: "An add or remove accessor expected".

In C#, events can be declared in two ways:

  1. Field-like events: public event EventHandler MyEvent; (The compiler generates storage and logic automatically).
  2. Custom events: You provide { ... } braces and explicitly define the add and remove accessors to handle subscription logic manually.

This error occurs when you open the curly braces { for an event but fail to provide the required add or remove blocks inside. Unlike properties (which use get and set), events strictly require add and remove.

Understanding Event Syntax

When defining an event with a body, you are responsible for managing the underlying delegate storage.

Valid Syntax:

public event EventHandler MyEvent
{
add { /* Add subscriber */ }
remove { /* Remove subscriber */ }
}

If the compiler sees the opening brace {, it stops treating the event as a "field-like event" and expects the custom accessor syntax immediately.

Scenario 1: Using Property Keywords (get/set)

This is a common mistake for developers used to writing properties. You might instinctively type get and set inside an event definition.

Example of error

public class Button
{
// ⛔️ Error CS1055: An add or remove accessor expected.
// Events do not have 'get' or 'set' accessors.
public event EventHandler Click
{
get;
set;
}
}

Solution: Use add and remove

You must use the correct keywords for events. Note that you also need to implement the storage (a private backing field) yourself when using this syntax.

public class Button
{
private EventHandler _click; // Backing field

public event EventHandler Click
{
// ✅ Correct: 'add' handles subscription (+=)
add
{
_click += value;
}

// ✅ Correct: 'remove' handles unsubscription (-=)
remove
{
_click -= value;
}
}
}

Scenario 2: Empty Event Bodies

Sometimes a developer might open the braces intending to implement logic later, or by accident, leaving the body empty.

Example of error

public class DataStream
{
// ⛔️ Error CS1055: The braces indicates a custom event,
// but no accessors are defined inside.
public event EventHandler DataReceived { }
}

Solution: Remove Braces or Implement

If you don't need custom logic, simply remove the braces and end the line with a semicolon. This creates a standard Field-like Event.

public class DataStream
{
// ✅ Correct: The compiler will now auto-generate the add/remove logic.
public event EventHandler DataReceived;
}

If you do need the braces (e.g., for CS0069 explicit interface implementation logic), you must write the add and remove blocks as shown in Scenario 1.

Conclusion

CS1055 is the compiler reminding you of the event contract.

  1. Check Keywords: Events use add and remove, not get and set.
  2. Check Braces: If you don't need custom logic, delete the { } and use a ;.
  3. Implement Logic: If you keep the braces, you must provide the implementation for adding and removing subscribers.