vb.net - An item with the same key has already been added to dictionary -


when running below code following error:

 system.argumentexception: item same key has been added.    @ system.throwhelper.throwargumentexception(exceptionresource resource)    @ system.collections.generic.dictionary`2.insert(tkey key, tvalue value, boolean add)    @ interfaces.interfacebase.getsettings()   

i using below code:

for each dr datarow in dsdata.tables("tbldata").rows       if interfacesettings.containskey(dr("settingsname").tostring.trim) = false           interfacesettings.add(dr("settingsname").tostring.trim, dr("settingsvalue").tostring.trim)       end if   next 

i have no duplicates in database table. idea why ever fail?

thanks in advance assistance.

how duplicate key exception occur when code checking key before attempting add it?

i think answer code shared. error occurs when thread checks condition , update dictionary interrupted thread updates dictionary , original thread same resulting in duplicate key exception.


Comments