asp.net - exception information : Message: An item with the same key has already been added -


i got an item same key error when load page.is there solution solve ? here's error

general information

 - - - - - - - - - - - - - - - - - - - - - - -    machinename: win-skec08hpaeb  fullname: innoark.apdms.common,  version=1.0.0.0, culture=neutral, publickeytoken=null  appdomainname:  /lm/w3svc/2/root-1-130120289473554687  threadidentity: innoark    1) exception information   - - - - - - - - - - - - - - - - - - - - - - -  exception type: system.argumentexception  message: item same key has  been added.  paramname: null  data:  system.collections.listdictionaryinternal  targetsite: void  throwargumentexception(system.exceptionresource)  helplink: null   source: mscorlib    stacktrace information   - - - - - - - - - - - - - - - - - - - - - - -  @ system.throwhelper.throwargumentexception(exceptionresource resource)   @ system.collections.generic.dictionary`2.insert(tkey key, tvalue  value, boolean add)  @  system.collections.generic.dictionary`2.add(tkey key, tvalue value)   @ innoark.apdms.webapp.controllers.simulationcontroller._list(guid  groupid, guid bctempid, string[] id, string[] volumeann, string[]  volumeavg, string[] costavg, string[] costann, string[] costifavg,  string[] costifann, boolean iseditbc, boolean isbc, boolean  issimulate, boolean issave) in  d:\dev\apdms\trunk\innoark.apdms.webapp\controllers\simulationcontroller.cs:line  2478 

sorry , here's code simulationcontroller line 2478 :

detaillist = new dictionary<string, object>();                     detaillist.add("id", entityid[j]);                     detaillist.add("volann", volann[j]);                     detaillist.add("volavg", volavg[j]);                     detaillist.add("vollatestann", vollatestann[j]);                     detaillist.add("vollatestavg", vollatestavg[j]);                     detaillist.add("cann", cann[j]);                     detaillist.add("cavg", cavg[j]);                     detaillist.add("cifann", cifann[j]);                     detaillist.add("cifavg", cifavg[j]);                     detaillist.add("code", code[j]);                     detaillist.add("islatest", islatest[j]);                     detaillist.add("isdirty", isdirty[j]);                     detaillist.add("curr", curr[j] == null ? "" : curr[j]);                     detaillist.add("nooforder", nooforder[j]);                     detaillist.add("isfilter", isfilter[j]);                     templist2.add(entityid[j].tostring(), detaillist); << line : 2478 

thanks trying answer question ? :)

this means dictionary named templist2 has key value in entityid[j].

looks wrong loop, or entityid contains duplicate values.

assuming it's second option, use .distinct():

entityid = entityid.distinct().tolist(); 

in case entityid plain array , not generic list, have such code instead:

entityid = entityid.tolist().distinct().toarray(); 

anyway avoid crash on cases, can add such validation:

if (templist2.containskey(entityid[j].tostring())) {     //already exists, can show alert here. } else {     templist2.add(entityid[j].tostring(), detaillist); } 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -