Index Out of Bound Error in Global.asax occuring at random times RRS feed

  • Question

  • User-1247255703 posted

    Hi All,

    I am getting an index out of bound error at odd times and completely random and only to some users. Below is the stack trace. Any idea? I tried Locking the object as per a previous thread but doesn't seem to help. Any idea why would this be occurring?

    I get Line 17: If Not OnlineVisitorsUtility.Visitors.ContainsKey(currentContext.Session.SessionID) Then Line 18: If HttpContext.Current.User.Identity.Name = [String].Empty Then Line 19: OnlineVisitorsUtility.Visitors.Add(currentContext.Session.SessionID, New WebsiteVisitor(currentContext)) Line 20: Else Line 21: OnlineVisitorsUtility.Visitors.Add(currentContext.Session.SessionID, New WebsiteVisitor(currentContext, HttpContext.Current.User.Identity.Name))

    Source File:global.asax Line: 19

    Stack Trace:

    [IndexOutOfRangeException: Index was outside the bounds of the array.] System.Collections.Generic.Dictionary2.Insert(TKey key, TValue value, Boolean add) +10425621 System.Collections.Generic.Dictionary2.Add(TKey key, TValue value) +12 ASP.global_asax.Session_Start(Object sender, EventArgs e) in D:\Projects\global.asax:19 System.Web.SessionState.SessionStateModule.RaiseOnStart(EventArgs e) +11278204 System.Web.SessionState.SessionStateModule.CompleteAcquireState() +366 System.Web.SessionState.SessionStateModule.BeginAcquireState(Object source, EventArgs e, AsyncCallback cb, Object extraData) +1281 System.Web.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +85 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +263

    Sunday, July 12, 2015 8:28 PM


  • User-84896714 posted

    Hi thoalice,

    Welcome to asp.net forums.


    [IndexOutOfRangeException: Index was outside the bounds of the array.] System.Collections.Generic.Dictionary

    This error often occurs in concurrent scene, I suggest use Thread-safe Dictionary instead of System.Collections.Generic.Dictionary. Link below is for your reference.

    Best Regards,
    Wang Li

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, July 13, 2015 10:37 PM