Fix for "An item with the same key has already been added" Exception

Posted by Bandi under ASP.NET on 8/1/2013 | Points: 10 | Views : 28257 | Status : [Member] [MVP] | Replies : 2
I got following error while using application with concurrent users...
System.ArgumentException: An item with the same key has already been added.
Server stack trace:
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
..........................

How to fix this exception..? I have checked property name and data types. there is no same name properties/variables.. And also cross checked base entity and derived entities..
If any one faced this kind of exception earlier, give me the workaround to fix the issue

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif



Responses

Posted by: Allemahesh on: 8/1/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
Dear Bandi,

You are using Dictionary to inset the values in it.
The dictionary will not allows any duplicate key to insert in it. So the error saying that you are try to inset duplicate key values into you dictionary .

Solution : Check if there is any duplicate values is inserting into you Dictionary.

Happy Coding.

Bandi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 8/2/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
I'm inserting & viewing data through application...
The above exception is not occurring for single user.. If there is concurrent users with same login then only this occurred...
We tried to insert 600 records with same values.... Error occurred at 4 times( i.e. for 4 records) during the process...

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Bandi, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response