Skip to main content

How to Resolve Error "CS1004: Duplicate 'modifier' modifier" in C#

The Compiler Error CS1004 is a syntax error caused by redundancy. The message reads: "Duplicate 'modifier' modifier".

In C#, declaration keywords (modifiers) such as public, private, static, readonly, virtual, and async must appear only once per definition. Repeating a keyword (e.g., public public) does not add extra emphasis or meaning; it simply violates the language's grammar rules.

This guide explains how to spot and fix these redundant keywords.

Understanding Modifier Rules

A declaration in C# typically follows this pattern:

[Attributes] [AccessModifier] [BehaviorModifiers] [Type] [Name]

Examples of modifiers:

  • Access: public, private, internal, protected
  • Behavior: static, readonly, virtual, override, abstract, async, sealed

The compiler scans these keywords. If it encounters the same keyword twice for the same member, it raises CS1004.

Scenario 1: Repeated Access Modifiers

This is the most common cause, usually resulting from a typo, a copy-paste error, or a bad Git merge where lines were duplicated.

Example of error

Typing public twice.

public class User
{
// ⛔️ Error CS1004: Duplicate 'public' modifier
public public string Name { get; set; }
}

Solution: Remove the Duplicate

Simply delete the extra keyword.

public class User
{
// ✅ Correct: Only one 'public' is allowed
public string Name { get; set; }
}
note

If you see public private, that is a different error (CS0107 - More than one protection modifier). CS1004 specifically refers to the same word appearing twice.

Scenario 2: Repeated Behavior Modifiers

This error applies to any modifier, not just access levels. It frequently happens when refactoring code (e.g., making a method async) and accidentally pasting the keyword without removing the old one, or when declaring constants.

Example of error

Repeating static or readonly.

public class Configuration
{
// ⛔️ Error CS1004: Duplicate 'static' modifier
public static static void Initialize()
{
}

// ⛔️ Error CS1004: Duplicate 'readonly' modifier
private readonly readonly int _id;
}

Solution: Ensure Uniqueness

Verify that each keyword appears only once in the declaration line.

public class Configuration
{
// ✅ Correct
public static void Initialize()
{
}

// ✅ Correct
private readonly int _id;
}

Conclusion

CS1004 is a simple grammar check.

  1. Check the Line: Look at the declaration causing the error.
  2. Find the Echo: Identify the word that appears twice (e.g., static ... static).
  3. Delete it: Remove the redundancy.