Skip to main content

How to Resolve Error "CS0107: More than one protection modifier" in C#

The Compiler Error CS0107 is an access control syntax error. The message reads: "More than one protection modifier".

C# uses Access Modifiers (like public, private, internal) to define which parts of your code can see and use a specific class, method, or variable. This error occurs when you apply two or more modifiers that contradict each other (e.g., declaring something as both public and private) or use a combination of compound modifiers that is not supported by the language.

This guide explains the valid access levels in C# and how to resolve conflicting modifiers.

Understanding Valid Modifiers​

An element in C# can only have one defined access level. However, some access levels are defined by two keywords working together (compound modifiers).

Valid Single Modifiers:

  • public (Visible to everyone)
  • private (Visible only to this class)
  • internal (Visible to this assembly/project)
  • protected (Visible to this class and derived classes)

Valid Compound Modifiers:

  • protected internal (Visible to this assembly OR derived classes)
  • private protected (Visible to this assembly AND derived classes - C# 7.2+)

Any combination outside of this list (like public private or public internal) triggers CS0107.

Scenario 1: Mutually Exclusive Modifiers​

The most common cause is accidental typing or copy-pasting, resulting in two contradictory keywords on the same line. An item cannot be "open to everyone" (public) and "hidden from everyone" (private) at the same time.

Example of error​

public class User
{
// ⛔️ Error CS0107: More than one protection modifier
// A property cannot be both public and private.
public private int Id { get; set; }
}

Solution: Choose One​

Decide on the intended visibility and remove the extra keyword.

public class User
{
// ✅ Correct: It is now strictly public
public int Id { get; set; }
}
note

If you wanted the Setter to be private but the Getter to be public, you apply the modifier to the accessor, not the property definition itself: public int Id { get; private set; }

Scenario 2: Invalid Compound Modifiers​

Developers sometimes try to combine modifiers to create custom access levels that C# does not support, such as trying to make something "Public to the world but also Protected."

Example of error​

public class BaseClass
{
// ⛔️ Error CS0107: 'public' and 'protected' cannot be combined.
public protected void DoWork()
{
}
}

Solution: Use Valid Combinations​

If you need mixed visibility, you must use the specific compound modifiers supported by C#.

  • Use protected internal if you want it accessible by any class in the same project, PLUS any subclasses in other projects.
  • Use private protected if you want it accessible by subclasses, but only if they are in the same project.
public class BaseClass
{
// ✅ Correct: Standard compound modifier
protected internal void DoWork()
{
// Accessible to this Assembly OR Derived classes
}
}

Conclusion​

CS0107 forces you to be clear about your security boundaries.

  1. Check for Typos: Ensure you didn't accidentally type public twice or mix private with public.
  2. Review Compounds: Ensure you are only using valid pairs (protected internal or private protected).
  3. Simplify: When in doubt, stick to the standard single keywords (public, private, internal).