locked
System.ArgumentException: An entry with the same key already exists. RRS feed

  • Question

  • User-316593 posted

    Hello to all. I'm  a newbie and I joined because I have an error that I just couldn't solve. It's System.ArgumentException: An entry with the same key already exists. error.

    Here is the whole stack trace:

    An entry with the same key already exists.
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.ArgumentException: An entry with the same key already exists.

    Source Error:
    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.


    Stack Trace:

    [ArgumentException: An entry with the same key already exists.]
    System.Collections.Specialized.ListDictionary.Add(Object key, Object value) +6157735
    System.Collections.Specialized.HybridDictionary.Add(Object key, Object value) +60
    System.Web.UI.StateBag.Add(String key, Object value) +126
    System.Web.UI.WebControls.Parameter.UpdateValue(HttpContext context, Control control) +77
    System.Web.UI.WebControls.ParameterCollection.UpdateValues(HttpContext context, Control control) +113
    System.Web.UI.WebControls.SqlDataSource.LoadCompleteEventHandler(Object sender, EventArgs e) +46
    System.EventHandler.Invoke(Object sender, EventArgs e) +0
    System.Web.UI.Page.OnLoadComplete(EventArgs e) +8876398
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2350

    I can't figure out what produces the error because it shows only frequently. For example: I am browsing my website and refreshing the page over and over and it' s ok for like 10 minutes and then all of a sudden it throws an error. then I refresh it once more and the error is gone.

    I just don't know when will it show and why, but after refreshing website only once it works perfect again.

    Please help me because I'm starting to freak out.

    Thanks in advance,

    marchetto271


     

    Thursday, August 11, 2011 11:33 AM

Answers

All replies

  • User707529390 posted

    Hello to all. I'm  a newbie and I joined because I have an error that I just couldn't solve. It's System.ArgumentException: An entry with the same key already exists. error.

    Here is the whole stack trace:

    An entry with the same key already exists.
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.ArgumentException: An entry with the same key already exists.

    Source Error:
    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.


    Stack Trace:

    [ArgumentException: An entry with the same key already exists.]
    System.Collections.Specialized.ListDictionary.Add(Object key, Object value) +6157735
    System.Collections.Specialized.HybridDictionary.Add(Object key, Object value) +60
    System.Web.UI.StateBag.Add(String key, Object value) +126
    System.Web.UI.WebControls.Parameter.UpdateValue(HttpContext context, Control control) +77
    System.Web.UI.WebControls.ParameterCollection.UpdateValues(HttpContext context, Control control) +113
    System.Web.UI.WebControls.SqlDataSource.LoadCompleteEventHandler(Object sender, EventArgs e) +46
    System.EventHandler.Invoke(Object sender, EventArgs e) +0
    System.Web.UI.Page.OnLoadComplete(EventArgs e) +8876398
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2350

    I can't figure out what produces the error because it shows only frequently. For example: I am browsing my website and refreshing the page over and over and it' s ok for like 10 minutes and then all of a sudden it throws an error. then I refresh it once more and the error is gone.

    I just don't know when will it show and why, but after refreshing website only once it works perfect again.

    Please help me because I'm starting to freak out.

    Thanks in advance,

    marchetto271


     

    Thursday, August 11, 2011 12:39 PM
  • User1105670391 posted

    find in your code the the class instance of 'ListDictionary' and find when the function 'Add' is called, 

    the error means there is an value pair with the same index already in the dictionay

    so do something like this:

    if (listdictionary.contains('key')) 
    {
      //put special code here to handle adding the same key
    }
    else
    {
      listdictionary.add(...)
    }

    Friday, August 12, 2011 3:40 PM
  • User-316593 posted

    Thanks, I'll try that!

    Sunday, August 14, 2011 5:57 PM
  • User-1694870838 posted

    Hi,

     In your Program,System.Collections.Specialized.ListDictionary.Add(Object key, Object value) you can add same key in a ListDictionary.

    About hoew to use ListDictionary you can refer to the link:http://msdn.microsoft.com/en-us/library/system.collections.specialized.listdictionary.add.aspx

    Best Regards,

    Damon

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, August 16, 2011 2:13 AM