CS0579
C# Programming Language
Severity: MinorWhat Does This Error Mean?
CS0579 means you applied the same attribute to a class, method, or property more than once — but that attribute does not allow duplicates. For example, writing [Obsolete] twice on the same method. Some attributes are designed to only appear once; if you apply them twice, C# rejects it. The fix is to remove the duplicate attribute, or to check whether the attribute supports multiple applications.
Affected Models
- .NET Framework
- .NET Core
- .NET 5+
- All C# versions
Common Causes
- Accidentally applying the same attribute twice to the same class, method, or property
- Copy-pasting code that already has an attribute and then adding the same attribute again
- Inheriting from a base class that already has the attribute applied, and then applying it again in the derived class
- Using both the short form and long form of an attribute — like [Obsolete] and [ObsoleteAttribute] — which are the same attribute
- An automatically generated code file (partial class) already has the attribute, and you applied it again in your hand-written part
How to Fix It
-
Find the class, method, or property with the duplicate attribute. Look above it for multiple lines starting with [AttributeName].
Remove one of the duplicate attribute lines. Keep the one with the correct settings if they differ.
-
Check for the long-form and short-form combination — [Obsolete] and [ObsoleteAttribute] are the same attribute. Remove one.
In C#, attributes can be referenced with or without the 'Attribute' suffix. [Serializable] and [SerializableAttribute] are identical. Pick one style and use it consistently.
-
If you have a partial class (split across multiple files), check all parts of the class for the same attribute.
Both files contribute to the same class. If both files have [Serializable] on the class, that is a duplicate — remove it from one file.
-
If you genuinely need to apply similar data more than once (like multiple [Route] or [Header] attributes), check the attribute's documentation to see if AllowMultiple = true is set.
Attributes that allow multiple applications are defined with [AttributeUsage(AllowMultiple = true)]. Common examples: [Authorize], [Route] in ASP.NET Core.
-
If you are the author of the attribute and want it to allow multiple applications, add [AttributeUsage(AttributeTargets.All, AllowMultiple = true)] to your attribute class.
Without AllowMultiple = true, applying the attribute more than once is a compile error.
When to Call a Professional
CS0579 is a straightforward compile-time error. Remove the duplicate attribute and the error will be resolved. If you need to apply similar information twice, check whether the attribute was designed to support multiple applications.
Frequently Asked Questions
What is an attribute in C#?
An attribute is a label you attach to code (classes, methods, properties, etc.) to add metadata. For example, [Obsolete] marks a method as outdated. [Serializable] marks a class as serializable. [TestMethod] marks a method as a unit test. Attributes are read by the compiler, IDE, frameworks, or reflection code at runtime. They look like [AttributeName] placed above the code element they apply to.
Can some attributes be applied multiple times?
Yes — some attributes are designed to appear multiple times on the same element. For example, in ASP.NET Core, [Authorize(Roles='Admin')] and [Authorize(Policy='RequireLogin')] can both be on the same controller method. An attribute supports this when its definition includes [AttributeUsage(AllowMultiple = true)]. If AllowMultiple is false (the default), applying it twice causes CS0579.
How do I check whether an attribute allows multiple applications?
Look at the attribute's definition in the documentation or source code. Find its [AttributeUsage(...)] decoration — if AllowMultiple = true is there, multiple applications are allowed. For .NET built-in attributes, check docs.microsoft.com and search for the attribute class. In Visual Studio, you can also press F12 on the attribute name to go to its definition.