Visual Studio: 'An item with the same key has already been added.'


Unknown build error, 'An item with the same key has already been added.'

The old error RG1000. This has been around for a while but still comes up from time to time. The most frequent cause of this error is having a duplicate referenced item in your project file. It's also an inconsistent error in that it usually allows you to build the project if you do it a second time.

csproj

<ItemGroup>
	<Resource Include="Assets\app.png" />
</ItemGroup>

<ItemGroup>
	<Resource Include="Assets\app.png" />
</ItemGroup>

The fix is to right click on your csproj, choose Edit Project File and then find and remove the duplicate resource. After this you should be able to right click on the project and Clean which should allow subsequent builds to work every build. If clean doesn't work manually go and clear the bin and obj folders.

Leave a comment

Please note that we won't show your email to others, or use it for sending unwanted emails. We will only use it to render your Gravatar image and to validate you as a real person.