Duplicate AssemblyVersion Attribute

C#Compiler Errors

C# Problem Overview


I have a project that generates following error on compilation:

> error CS0579: Duplicate 'AssemblyVersion' attribute

I have checked the file AssemblyInfo.cs and it looks like there is no duplication there.

I found this article on MSDN which addresses a similar problem and following the suggestion in this article fixes the problem as well.

Can anyone tell me what's going on here? Does it happen only in case of having two or more projects with classes having similar names? Or is it something else?

C# Solutions


Solution 1 - C#

Starting from Visual Studio 2017 another solution to keep using the AssemblyInfo.cs file is to turn off automatic assembly info generation like this:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
  </PropertyGroup>
</Project>

I personally find it very useful for projects which need to support both .NET Framework and .NET Standard.

Solution 2 - C#

I have also run into this issue in the past, so I am going to assume that your build process provides assembly information separately to providing versioning. And that causes a duplication as your project also has that info in the AssemblyInfo.cs file. So remove the file and I think it should work.

Solution 3 - C#

When converting an older project to .NET Core, most of the information that was in the AssemblyInfo.cs can now be set on the project itself. Open the project properties and select the Package tab to see the new settings.

The Eric L. Anderson's post "Duplicate ‘System.Reflection.AssemblyCompanyAttribute’ attribute" describes 3 options :

  • remove the conflicting items from the AssemblyInfo.cs file,
  • completely delete the file or
  • disable GenerateAssemblyInfo (as suggested in another answer by Serge Semenov)

Solution 4 - C#

In my case, there where a subfolder in a project that was a project folder it self:

  • file system:

    • c:\projects\webapi\wepapi.csproj
    • c:\projects\webapi\tests\wepapitests.csproj
  • solution

    • webapi (folder and project)
      • tests (folder)
  • tests (folder and project)

Then i had to remove the subfolder "tests" from the "webapi" project.

Solution 5 - C#

I had the same error and it was underlining the Assembly Vesrion and Assembly File Version so reading Luqi answer I just added them as comments and the error was solved

// AssemblyVersion is the CLR version. Change this only when making breaking    changes
//[assembly: AssemblyVersion("3.1.*")]
// AssemblyFileVersion should ideally be changed with each build, and should help identify the origin of a build
//[assembly: AssemblyFileVersion("3.1.0.0")]

Solution 6 - C#

There must be already a AssemblyInfo.cs file in the project here: enter image description here

To solve:

  • Delete any one AssemblyInfo.cs

Solution 7 - C#

In my case, some temporary *.cs files generated during compilation got accidentally added to the project.

The files were from the obj\Debug directory, so they definitely shouldn't have been added to the solution. A *.cs wildcard went a little crazy and added them incorrectly.

Deleting these files fixed the problem.

Solution 8 - C#

I came across the same when tried add GitVersion tool to update my version in AssemblyInfo.cs. Use VS2017 and .NET Core project. So I just mixed both worlds. My AssemblyInfo.cs contains only version info that was generated by GitVersion tool, my csproj contains remaingin things. Please note I don't use <GenerateAssemblyInfo>false</GenerateAssemblyInfo> I use attributes related to version only (see below). More details here AssemblyInfo properties.

AssemblyInfo.cs

[assembly: AssemblyVersion("0.2.1.0")]
[assembly: AssemblyFileVersion("0.2.1.0")]
[assembly: AssemblyInformationalVersion("0.2.1+13.Branch.master.Sha.119c35af0f529e92e0f75a5e6d8373912d457818")]

my.csproj contains all related to other assembly attributes:

<PropertyGroup>
   ...
  <Company>SOME Company </Company>
  <Authors>Some Authors</Authors>
  <Product>SOME Product</Product>
   ...
  <GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
  <GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute>
  <GenerateAssemblyInformationalVersionAttribute>false</GenerateAssemblyInformationalVersionAttribute>
</PropertyGroup>

csproj maps to package tab at project properties

Solution 9 - C#

For me it was that AssembyInfo.cs and SolutionInfo.cs had different values. So check these files as well. I just removed the version from one of them.

Solution 10 - C#

My error occurred because, somehow, there was an obj folder created inside my controllers folder. Just do a search in your application for a line inside your Assemblyinfo.cs. There may be a duplicate somewhere.

Solution 11 - C#

You can remove bin and obj file and clear the cache of the project. My issue was fixed from that.

Solution 12 - C#

Yet another solution when upgrading core to VS2017 is to remove them in the properties\assemblyinfo.cs file.

Since they now are stored in the project.

Solution 13 - C#

This usually happens for me if I compiled the project in Visual Studio 2017 & then I try to rebuild & run it with .NET Core with the command line command "dotnet run".

Simply deleting all the "bin" & "obj" folders - both inside "ClientApp" & directly in the project folder - allowed the .NET Core command "dotnet run" to rebuild & run successfully.

Solution 14 - C#

I ran into this recently with no changes to source, but after experimenting with some new project references. I got into a state where this error was appearing even after reverting all changes in the branch.

Cleaning the branch resolved it for me:

git clean -xfd

Solution 15 - C#

I found this answer on msdn, that explains marking the file as Content and then Copy to Output = If Newer. See article below:

https://social.msdn.microsoft.com/Forums/en-US/8671bdff-9b16-4b49-ba9e-227cc4df31b2/compile-error-cs0579-duplicate-assemblyversion-attribute?forum=vsgatk

GH

Solution 16 - C#

Edit you AssemblyInfo.cs and #if !NETCOREAPP3_0 ... #endif

using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.

#if !NETCOREAPP3_0  

[assembly: AssemblyTitle(".Net Core Testing")]
[assembly: AssemblyDescription(".Net Core")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct(".Net Core")]
[assembly: AssemblyCopyright("Copyright ©")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components.  If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("000b119c-2445-4977-8604-d7a736003d34")]

// Version information for an assembly consists of the following four values:
//
//      Major Version
//      Minor Version
//      Build Number
//      Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

#endif

Solution 17 - C#

I got this error when I did put 2 projects in the same directory. If I have a directory with an solution and I put a separate Web and Data directory in it compiles right.

Solution 18 - C#

I had this issue when my main project was in the same folder as the solution, then I had a separate project in the same solution located in a sub folder, and that separate project used the main project as a reference. This caused the main project to detect the sub folder bin & obj folders which created duplicate references.

Solution 19 - C#

If you're having this problem in a Build Pipeline on Azure DevOps, try putting the Build Action as "Content" and Copy to Output Directory equal to "Copy if newer" in the AssembyInfo.cs file properties.

Solution 20 - C#

When you create a project, Visual Studio sets it up to compile & generate a corresponding assembly. Each project generates 1 assembly, and so each has a corresponding assembly configuration to generate its assembly from.

The problem is when you create more than one project that each can generate their own assembly, and then include one of these projects in the other.

In this scenario, Visual Studio gets confused and doesn't know which config file to go off of to generate the single assembly for the project -- it finds the second assembly configuration in the included project and says "HEY, DUPLICATE! You've given me two sets of instructions for generating my assembly!"

But sometimes you still want the included project to be able to generate an assembly on it's own, but not when it is being included in another project.

To obtain this, one solution is to add conditional defines to the including project (found in project Properties). Then change the assembly config in the included project to look for this conditional define. If it is defined (by the including project), then the config can skip over it's content -- this will result in only 1 config found by VS -- the one from the including project -- problem solved!

Solution 21 - C#

My error was that I was also referencing another file in my project, which was also containing a value for the attribute "AssemblyVersion". I removed that attribute from one of the file and it is now working properly.

The key is to make sure that this value is not declared more than once in any file in your project.

Solution 22 - C#

obj\Debug\netstandard2.0\PacktLibrary.AssemblyInfo.cs(15,12): error CS0579: Duplicate 'System.Reflection.AssemblyConfigurationAttribute' attribute [c:\Users\John_Tosh1\Documents\C#8.0and.NetCore3.0\Code\Chapter05\PacktLibrary\PacktLibrary.csproj]
obj\Debug\netstandard2.0\PacktLibrary.AssemblyInfo.cs(16,12): error CS0579: Duplicate 'System.Reflection.AssemblyFileVersionAttribute' attribute [c:\Users\John_Tosh1\Documents\C#8.0and.NetCore3.0\Code\Chapter05\PacktLibrary\PacktLibrary.csproj]
obj\Debug\netstandard2.0\PacktLibrary.AssemblyInfo.cs(17,12): error CS0579: Duplicate 'System.Reflection.AssemblyInformationalVersionAttribute' attribute [c:\Users\John_Tosh1\Documents\C#8.0and.NetCore3.0\Code\Chapter05\PacktLibrary\PacktLibrary.csproj]
obj\Debug\netstandard2.0\PacktLibrary.AssemblyInfo.cs(18,12): error CS0579: Duplicate 'System.Reflection.AssemblyProductAttribute' attribute [c:\Users\John_Tosh1\Documents\C#8.0and.NetCore3.0\Code\Chapter05\PacktLibrary\PacktLibrary.csproj]
obj\Debug\netstandard2.0\PacktLibrary.AssemblyInfo.cs(19,12): error CS0579: Duplicate 'System.Reflection.AssemblyTitleAttribute' attribute [c:\Users\John_Tosh1\Documents\C#8.0and.NetCore3.0\Code\Chapter05\PacktLibrary\PacktLibrary.csproj]
obj\Debug\netstandard2.0\PacktLibrary.AssemblyInfo.cs(20,12): error CS0579: Duplicate 'System.Reflection.AssemblyVersionAttribute' attribute [c:\Users\John_Tosh1\Documents\C#8.0and.NetCore3.0\Code\Chapter05\PacktLibrary\PacktLibrary.csproj]

I believe my Library folder was corrupted by an inadvertent creation of another class library.I deleted the library an all associated file but the problem persisted. I found a workaround by deleting ALL bin and obj folders in the directory. The build was ok previously but found a subfolder that had the same assemblyinfo.cs file.

Solution 23 - C#

This issue is a reference conflict which is mostly peculiar to VS 2017.

I solved this same error by simply commenting out lines 7 -14 as well as Assembly version codes at the bottom of the page on AssemblyInfo.cs

It removed all the duplicate references and the project was able to build again.

Solution 24 - C#

I got the error Just after switching from .NET Framework to .NET Core. I have 2 class library projects in my Visual Studio solution. I realized that 1 of the projects has a file named AssemblyInfo.cs while the other project does not have the file. The file is located under the Properties folder. I simply delete the Properties folder and all works fine.

Solution 25 - C#

I have being struggling with this issue, but my problem was much easier to solve.

I had copied OBJ folder to "OBJ___" name to do some compilation tests.

So, I don't know why, this folder was being also compiled, creating the assembly attributes duplication.

I simply deleted the "OBJ___" folder and could compile successfuly.

Solution 26 - C#

I just helped a team member resolve this issue by renaming the repo folder the re-cloning the repo. This was only an issue for one developer as everyone else on the team was able to build master without hitting this error so we knew the problem wasn't an issue in source.

We did try deleting bin and obj folders and doing a git clean -xfd but neither of those resolved the issue. Starting fresh with a clean copy of the repo did the trick in this case.

Solution 27 - C#

I've being struggling with this issue too. In my case ,I had put solution and project in a same place .So I had problem .After I chose a folder for solution and put the project in this solution ,it worked properly.

Solution 28 - C#

For anyone else running into this issue, I diagnosed it for a coworker, who claimed she had changed nothing, but who it turned out had accidentally copied a code folder and hadn't realized it. So that was fun to figure out.

Lesson: Assume everyone lies.

Solution 29 - C#

In my case, one of my colleagues had removed a Console App used for testing purposes, that was placed in the same directory as our Api, and then committed to Git. When I later pulled from Git, the console app itself was ofcourse gone, but it's bin and obj folders was still there, resulting in the AssemblyInfo.cs file being present in both the root application dir and the subdir for the old console app. Simply removing the bin and obj folders for the old console app resolved the issue.

ASP.NET Core 3.1

Solution 30 - C#

I got these errors because I tried to temporarily rename the obj folder to obj_, and then it's included in the project automatically. Then the assembly.cs in it began to fight with the right one in obj folder generated later.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAamirView Question on Stackoverflow
Solution 1 - C#Serge SemenovView Answer on Stackoverflow
Solution 2 - C#luqiView Answer on Stackoverflow
Solution 3 - C#Michael FreidgeimView Answer on Stackoverflow
Solution 4 - C#heringerView Answer on Stackoverflow
Solution 5 - C#Pantelitsa MavrovouniotiView Answer on Stackoverflow
Solution 6 - C#Tejas KatakdhondView Answer on Stackoverflow
Solution 7 - C#Nate BarbettiniView Answer on Stackoverflow
Solution 8 - C#AlezisView Answer on Stackoverflow
Solution 9 - C#Mariusz.WView Answer on Stackoverflow
Solution 10 - C#Dwayne LoveView Answer on Stackoverflow
Solution 11 - C#AdithyaView Answer on Stackoverflow
Solution 12 - C#Thomas KoelleView Answer on Stackoverflow
Solution 13 - C#WilliamView Answer on Stackoverflow
Solution 14 - C#Christopher ScottView Answer on Stackoverflow
Solution 15 - C#Gary HenshallView Answer on Stackoverflow
Solution 16 - C#SourcephyView Answer on Stackoverflow
Solution 17 - C#Herman Van Der BlomView Answer on Stackoverflow
Solution 18 - C#Mark EntinghView Answer on Stackoverflow
Solution 19 - C#Marcello Teófilo FontelesView Answer on Stackoverflow
Solution 20 - C#AnonymouseITManFromUSView Answer on Stackoverflow
Solution 21 - C#Antoine DijouxView Answer on Stackoverflow
Solution 22 - C#John FlurkeyView Answer on Stackoverflow
Solution 23 - C#AdeakinweView Answer on Stackoverflow
Solution 24 - C#Felix AugustinView Answer on Stackoverflow
Solution 25 - C#Allan ZeidlerView Answer on Stackoverflow
Solution 26 - C#SamView Answer on Stackoverflow
Solution 27 - C#Ali MahdianView Answer on Stackoverflow
Solution 28 - C#user169771View Answer on Stackoverflow
Solution 29 - C#user3276657View Answer on Stackoverflow
Solution 30 - C#chenyView Answer on Stackoverflow