title: Index outside of bound exception
body: <p>I have the following code, and somehow yesterday evening it had thrown a lot of exceptions:</p>
  
  <blockquote>
    <p>Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.IndexOutOfRangeException: Index was outside the bounds of the array.
       at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)</p>
  </blockquote>
  
  <p>I just don't see how this is possible, I check for null and if the key is available. This is the only method where lastTimeoutCheck is used.</p>
  
  <pre><code>private static Dictionary&lt;string, DateTime&gt; lastTimeoutCheck;
  private static readonly object CacheLock = new object();
  private static void CheckTimeout(string groupName)
  {
      if (lastTimeoutCheck == null)
      {
          lastTimeoutCheck = new Dictionary&lt;string, DateTime&gt;();
          return;
      }
      if (!lastTimeoutCheck.ContainsKey(groupName))
      {
          lastTimeoutCheck.Add(groupName, DateTime.UtcNow);
          return;
      }
  
      if (lastTimeoutCheck[groupName] &lt;
          DateTime.UtcNow.AddMinutes(-GroupConfigSection.TimeOutCheckMinutes))
      {
          lock (CheckLock)
          {
              if (lastTimeoutCheck[groupName] &lt;
                  DateTime.UtcNow.AddMinutes(-GroupConfigSection.TimeOutCheckMinutes))
              {
                  GroupHolder groupHolder =
                      (GroupHolder) System.Web.HttpContext.Current.Cache.Get(groupName);
                  if (groupHolder != null)
                  {
                      groupHolder.UpdateTime();
                  }
  
                  lastTimeoutCheck[groupName] = DateTime.UtcNow;
              }
          }
      }
  }
  </code></pre>