Dictionary is returning false on ContainsKey after item is added
        Posted  
        
            by Karel Frajtak
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Karel Frajtak
        
        
        
        Published on 2010-04-25T09:42:23Z
        Indexed on 
            2010/04/25
            9:53 UTC
        
        
        Read the original article
        Hit count: 524
        
I have a dictionary declared as follows
IDictionary<string, object> _objectIds = new Dictionary<string, object>();
I was experiencing some problems with it and it discovered that the instance returned false as a result of ContainsKey method and from the watch window I was sure that the item was there. So I created helper method
private bool IdsContainsKey(string key)
{
  lock (syncObject)
  {
     lock (_objectIds)
     {
       if (_objectIds.ContainsKey(key))
         return true; // A
       if (_objectIds.ContainsKey(key))
         return true; // B
       return _objectIds.ContainsKey(key); // C
     }
  }
}
During my debugging session I run into situation when the method exited in place B and sometimes I made to C returning true. Can anybody help me? Thanks.
© Stack Overflow or respective owner