VS2010 "An item with the same key has already been added"
Asked Answered
G

10

27

I recently installed Visual Studio 2010 and copied and converted an old VS2005 solution to VS2010

When I edit this solution, if I try to change a control's .image property, VS2010 creates a message box telling me that "An item with the same key has already been added", and won't let me browse for an image.

I can add images for any other solution, even others ported from VS2005, but not this one. Any idea what I'm doing wrong?

Gadfly answered 9/6, 2010 at 7:45 Comment(1)
Very similar problem. Getting the error when publishing: #13299098Hickson
G
24

I worked this out thanks to a search. The solution is to never create a .resx file with the name "Resources.resx" because it conflicts with the "Resources.resx" files that can be automatically created in the project's properties dialog.

Once I renamed Resources.resx to Icons.resx, I was able to change the image property for anything in the solution.

Gadfly answered 14/6, 2010 at 3:5 Comment(0)
J
19

I had the same experience but due to duplicate image resources in the .csproj file:

<Resource Include="Images\trigger-ModuleSelector1.png" />
<Resource Include="Images\trigger-ModuleSelector2.png" />
<Resource Include="Images\document.png" />
<Resource Include="Images\folder.png" />
<Resource Include="Images\trigger-ModuleSelector1.png" />
<Resource Include="Images\trigger-ModuleSelector2.png" />

Probably from a Merge Gone Wild(tm).

Same symptoms--regular build OK, rebuild fails. Remove the duplicate resource entries to fix the problem.

Junina answered 18/7, 2012 at 5:13 Comment(0)
L
12

Regarding Visual Studio 2015

The problem I was having was I could not load a project or re-add it to ANY solution. I would get the same error reported by others which is

Project '...' could not be opened because the Visual C# compiler could not
be created. An item with the same key has already been added.

This is going to sound overly simplistic, but when you get this error close ALL Visual Studio instances. Open the solution you were having trouble with and try again. This worked for me.

Learn answered 22/9, 2016 at 23:45 Comment(4)
Getting crazy with this error. Modifying csproj, not working. Proj properties, doesn't help. Close the damn VS and open the solution again, work like magic.Mostly
I just went to File > Close Solution and reopened the solution again, seemed to fix it for me!Stater
This works but it is not the solution. Same problem here.Lolanthe
After closing both SSMS and VS2015 the problem went away when the VS project was reopened.Gean
P
7

Running VS2010, I was able to fix this error by resetting the environment:

Tools > Import and Export Settings > Reset all settings
Pompei answered 29/10, 2013 at 20:53 Comment(0)
S
2

*in vs2015 if you get "An item with the same key has already been added" like image bellowm delete iis configuration in your csproj file

enter image description here

yours could be different but should be similar to following

 <ProjectExtensions>
    <VisualStudio>
      <FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
        <WebProjectProperties>
          <UseIIS>True</UseIIS>
          <AutoAssignPort>True</AutoAssignPort>
          <DevelopmentServerPort>32049</DevelopmentServerPort>
          <DevelopmentServerVPath>/</DevelopmentServerVPath>
          <IISUrl>http://localhost:32049</IISUrl>
          <NTLMAuthentication>False</NTLMAuthentication>
          <UseCustomServer>False</UseCustomServer>
          <CustomServerUrl>
          </CustomServerUrl>
          <SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile>
        </WebProjectProperties>
      </FlavorProperties>
    </VisualStudio>
  </ProjectExtensions>
Sidewalk answered 11/5, 2016 at 1:49 Comment(1)
You can also just turn UseIIS to false.Frown
A
1

I just had this same problem, but I didn't have any "Resources.resx" file in my solution (I didn't have any *.resx files, for that matter). My problem came because my .vcxproj project file was trying to use a file twice. I had added a custom build step for my protobuf files and added all my *.proto files to my project. However, a rouge .proto file appeared twice. Getting rid of the duplicate solved the problem.

So if you're having the same problem and you don't have any Resources.resx file, try looking at your .vcxproj file and making sure there aren't any other files that are getting duplicated.

Averell answered 23/3, 2012 at 1:5 Comment(0)
N
1

go inside properties/PublishProfiles, open the .pubxml file and check to see if your connection strings have been repeated. I had this issue, removed all the duplicate connection strings to leave one remaining and it solved my issue.

Nablus answered 24/3, 2017 at 12:3 Comment(0)
T
0

If you get this error during a SSDT Publish action, check you have not duplicated SqlCmdVariable entries in the Publish.xml file.

Taxeme answered 10/11, 2015 at 14:8 Comment(0)
B
0

For info: I had the same problem when changing an image properties in a WPF project from Resource to SplashScreen - once changed, the error would appear until the project was cleaned and rebuilt. Even before the clean, I could not see the duplication in the csproj file, editing in notepad++, so it had me searching for a bit!

Battaglia answered 6/8, 2021 at 11:28 Comment(0)
S
0

In case, it might help someone.

I got the same error in a project where most of the files I added from another project in same solution but I added those files as Add As Link

It seems like Add As Link requires file name to be unique across whole project. If you add file "example.cs" which is already exist in another folder/namespace of project, you will get this error.

Make sure files you've added using Add As Link have unique names.

Strick answered 16/2, 2023 at 13:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.