Windows Develop Bookmark and Share   
 index > Windows Forms Designer > System.ArgumentException : an item with the same key has already been added
 

System.ArgumentException : an item with the same key has already been added

[ArgumentException: an item with the same key has already been added]
System.throwHelper.throwArgumentException(ExceptionResource resource) +51
System.Collections.Generic.Dictionary'2.Insert(Tkey Key,Tvalue value,Boolean add) +7462172
System.Web.Query.Dynamic.ClassFactory.GetDynamicClass(IEnumerable '1 properties) +122
System.Web.Query.Dynamic.ExpressionParser.ParseNew() +406
System.Web.Query.Dynamic.ExpressionParser.ParseIdentifier() +230
System.Web.Query.Dynamic.ExpressionParser.ParsePrimaryStart() +34
System.Web.Query.Dynamic.ExpressionParser.ParsePrimary() +13
System.Web.Query.Dynamic.ExpressionParser.ParseUnary() +259

Above written lines are the errors coming in my project. These errors are coming very rearly.

If anyone have the solution i shall be very thankful.
Please reply.
Dheer_brain  Wednesday, July 08, 2009 12:10 PM

You're using a dictionary and you're trying to add an item with same key. Check code, avoid that.

Dictionary.add("key1","item1")
Dictionary.add("key2","item2")
Dictionary.add("key1","item3") << not allowed.

Check what part of your code is causing that.



Thanks

- Omie
Someone makes my heart skip a clock cycle !
  • Marked As Answer byAland LiMSFT, ModeratorTuesday, July 14, 2009 2:32 AM
  • Edited byOmie Wednesday, July 08, 2009 12:44 PM
  • Edited byOmie Wednesday, July 08, 2009 12:44 PM
  •  
Omie  Wednesday, July 08, 2009 12:42 PM

Hi Dheer_brain,

From my experience, the root cause is that you add an item whose key is already contained in the dictionary.

If you want to allow the later item override the former item, please follow this:
"key"] = "value";Otherwise, please follow this:(dic.ContainsKey("key") == false) dic.Add("key", "value");

Let me know if this helps.
Aland Li


Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
Aland Li  Friday, July 10, 2009 3:47 PM

You're using a dictionary and you're trying to add an item with same key. Check code, avoid that.

Dictionary.add("key1","item1")
Dictionary.add("key2","item2")
Dictionary.add("key1","item3") << not allowed.

Check what part of your code is causing that.



Thanks

- Omie
Someone makes my heart skip a clock cycle !
  • Marked As Answer byAland LiMSFT, ModeratorTuesday, July 14, 2009 2:32 AM
  • Edited byOmie Wednesday, July 08, 2009 12:44 PM
  • Edited byOmie Wednesday, July 08, 2009 12:44 PM
  •  
Omie  Wednesday, July 08, 2009 12:42 PM

Hi Dheer_brain,

From my experience, the root cause is that you add an item whose key is already contained in the dictionary.

If you want to allow the later item override the former item, please follow this:
"key"] = "value";Otherwise, please follow this:(dic.ContainsKey("key") == false) dic.Add("key", "value");

Let me know if this helps.
Aland Li


Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
Aland Li  Friday, July 10, 2009 3:47 PM

You can use google to search for other answers

Custom Search

More Threads

• Scrolling Custom Control/Component
• After running application (F5) Controls disappear from designer, now invisible
• MouseHover Event for Form Buttons (help please)
• Changing default control spacing used by snaplines
• Clicking on a form component creates an event method too easily
• mouseover
• Can't see form in design mode
• Visual Studio 2005 Reinstallation Critical problem
• Screen Refresh Problem
• Does .NET has this component built in ?