29

I recently added some copyright information to a set of C# projects (dlls) via the Properties->Application->Assembly Information button. I have several such projects in a single solution. Upon compilation I get error message of the type:

error CS0579: Duplicate 'XXX' attribute

where 'XXX' is the name of one of the attributes I specified (e.g. AssemblyFileVersionAttribute)

Googling I found that in the case of a class that is derived from the Attribute class, duplicates can be permitted by use of:

[System.AttributeUsage(System.AttributeTargets.All, AllowMultiple=true)]
class NewAttribute : System.Attribute { }

But in my case, I have added these attributes via the properties dialog and have statements (in AssemblyInfo.cs for each project) such as:

[assembly: AssemblyCompanyAttribute("My Company")]
[assembly: AssemblyProductAttribute("My Product")]
[assembly: AssemblyCopyrightAttribute("© 2012 My Company, All Rights Reserved.")]
[assembly: AssemblyVersionAttribute("13.0.0.0")]
[assembly: AssemblyFileVersionAttribute("1.0.0.0")]

and do not have any manually derived attribute classes I can attach any qualifiers to.

How do I solve this duplicate issue?

  • 4
    have you done a global search in your project for `AssemblyFileVersion` ? – Marc Gravell May 14 '12 at 19:55
  • 1
    The `AssemblyFileVersionAttribute` targets the entire assembly, as you know, so maybe you have more than one .cs-file (in the same project) that specify the attribute? – Jeppe Stig Nielsen May 14 '12 at 20:00
  • You can see the `AttributeUsageAttribute` that `AssemblyFileVersionAttribute` possesses here: [MSDN doc](http://msdn.microsoft.com/en-us/library/system.reflection.assemblyfileversionattribute.aspx) – Jeppe Stig Nielsen May 14 '12 at 20:03

5 Answers5

23

By adding this in .csproj file solved the issue

 <PropertyGroup>
    <TargetFramework>netcoreapp2.1</TargetFramework>
    <GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
        <GenerateAssemblyDescriptionAttribute>false</GenerateAssemblyDescriptionAttribute>
        <GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
        <GenerateAssemblyTitleAttribute>false</GenerateAssemblyTitleAttribute>
  </PropertyGroup>

As Bob suggested, if you don't want to add them individually, you can add

<GenerateAssemblyInfo>false</GenerateAssemblyInfo>   

to the <PropertyGroup>.

Matt
  • 25,467
  • 18
  • 120
  • 187
Vishnu Sharma
  • 291
  • 5
  • 9
  • 1
    Thanks it helped me alot. – Kotdroid Nov 22 '19 at 19:34
  • 4
    Instead of adding them individually, you can simply add `false` – Bob Dec 18 '20 at 21:43
  • While this worked for me, I wasn't satisfied this was the correct solution. I had previously converted the assembly I was working on from .NET 4.7.2 to NET Standard, and in doing so had copied the Properties directory containing AssemblyInfo.cs file. This is where the conflict arose as Net Standard does not require AssemblyInfo.cs. I removed the Properties directory and file and now longer receive the compiler error. – rantlr Jun 11 '21 at 13:41
  • I agree with @rantlr - this seems like a band-aid rather than a root cause correction. However, in my case, this is an assembly that is also published as a NuGet package, and I suspect a duplication in NuGet properties and Assembly properties, as a bug in VS. This solution worked to stifle the issue, as I don't want to wait for MS to fix VS... – Jay Imerman Jan 23 '23 at 21:06
21

I think you already specified those attributes in Assembly Information window of Project Properties. If you did this, please remove those attributes from Assembly Information.

rishad2m8
  • 1,365
  • 20
  • 27
2

Add<GenerateAssemblyInfo>false</GenerateAssemblyInfo>to the <PropertyGroup>.

Amir Touitou
  • 3,141
  • 1
  • 35
  • 31
1

Faced similar duplicate attribute issue CS0579.

By removing out directory from the project solved the issue for me.

Faizan
  • 11
  • 1
0

We had the issue with visual studio 2022 (17.3.2) and updating visual studio solved the error.

horotab
  • 675
  • 3
  • 20