Compiler Error
CS0275 – ‘accessor’: accessibility modifiers may not be used on accessors in an interface
Reason for the Error
You’ll get this error in your C# code when you try to use an access modifier on any of the accessors of the property in an interface.
For example, lets try to compile the below code snippet.
using System; namespace DeveloperPublishNamespace { public interface IEmployee { int Id { get; internal set; } } class Program { static void Main(string[] args) { Console.WriteLine("Hello World!"); } } }
You’ll receive the error code CS0275 because you have specified the access modifier internal for the set accessor in the IEmployee interface.
CS0275 – ‘accessor’: accessibility modifiers may not be used on accessors in an interface ‘Employee.Id’ DeveloperPublish C:\Users\Senthil\source\repos\ConsoleApp3\ConsoleApp3\Program.cs 9 Active
Solution
You can fix this error in your C# program by removing the access modifier as shown below. Also note that if you are using the latest version of C# (For example : C# 8, you’ll not see this error).
using System; namespace DeveloperPublishNamespace { public interface IEmployee { int Id { get; set; } } class Program { static void Main(string[] args) { Console.WriteLine("Hello World!"); } } }