Skip to main content

How to Resolve Error "CS0275: Accessibility modifiers may not be used on accessors in an interface" in C#

The Compiler Error CS0275 is a syntax error regarding Interface Definitions. The message reads: "'accessor': accessibility modifiers may not be used on accessors in an interface".

In C#, an interface defines a contract that implementing classes must fulfill. Traditionally, all members of an interface are implicitly public. While C# 8.0 introduced the ability to add access modifiers to interface members (for internal logic or static helpers), you are strictly forbidden from placing access modifiers (like public, private, protected, internal) directly on the get or set accessors of a property.

This guide explains why this restriction exists and how to correctly define interface properties.

Understanding Interface Contracts

When you define a property in an interface:

int Count { get; set; }

You are saying: "Any class implementing this interface must provide a public Getter and a public Setter for Count."

Since the purpose of an interface is to expose members to the outside world, the accessors are implicitly public. Adding modifiers to them is either redundant (if public) or contradictory to the concept of an interface contract (if private/protected).

Scenario 1: Redundant public Modifiers

Developers coming from other languages or explicit coding styles often try to add the public keyword to everything.

Example of error:

public interface IUser
{
// ⛔️ Error CS0275: Accessibility modifiers may not be used on accessors in an interface
// You cannot write 'public get' or 'public set' here.
string Name { public get; public set; }
}

Scenario 2: Trying to Restrict Accessors

Sometimes developers want to define an interface where the property can be read by everyone (get), but only written to by the class itself (private set).

You cannot express this "asymmetric" implementation detail in the interface. An interface only describes what is available to the consumer of the interface. If the setter is private, it is not part of the interface contract.

Example of error:

public interface IConfig
{
// ⛔️ Error CS0275: You cannot hide the setter in the interface.
// If it's private, it shouldn't be here at all.
string ApiKey { get; private set; }
}

Solution: Simplify the Declaration

To fix this, simply remove all access modifiers from the get and set keywords.

Solution

public interface IUser
{
// ✅ Correct: Implicitly public.
string Name { get; set; }
}

Handling Read-Only Contracts

If you want the property to be Read-Only for the consumer of the interface (even if the implementing class has a private setter), simply omit the set accessor from the interface.

public interface IConfig
{
// ✅ Correct: The contract only guarantees 'get'.
// The implementing class can still have a 'private set' or 'init',
// but the interface doesn't care about it.
string ApiKey { get; }
}

// Implementation
public class Config : IConfig
{
public string ApiKey { get; private set; } // Valid implementation
}
note

C# 8.0+ Default Implementations: Even though C# 8.0 allows defining private members in interfaces (for default method logic), the specific rule prohibiting modifiers on accessors (get/set) remains.

Conclusion

CS0275 keeps interface definitions clean and purely contractual.

  1. Remove Modifiers: Delete public, private, or protected from inside the { get; set; } block.
  2. Define Scope: If you don't want a setter to be public, do not include it in the interface definition at all.