Brian,
Well, if an object is stored as a key, then GetHashCode is called on it.
Then, the reference is put into a bucket, and then if there is more than one
item in the bucket, it calls Equals on those items.
If you have a custom implementation of GetHashCode (which you should
call if you override Equals), and that implementation is effected by
properties that can be changed, then this could very well be the case. You
might have added a key with a custom implementation of Equals/GetHashCode
and then changed a property on the object which affected the generation of
the key when you wanted to retrieve the item.
If this is the case, this is not an issue with the Dictionary, but what
you are using as the key.
--
- Nicholas Paldino [.NET/C# MVP]
-
mv*@spam.guard.caspershouse.com
"Brian Richards" <br*******@gmail.com> wrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
The collection is not being modified in other threads. I would have
expected
an Exception were that the case. We're investigating the possibility of it
being a hashing problem. Could it be that if you modify an object used as
a
key so that it's hashcode changes you don't get the match with the call to
ContainsKey(...). I don't know if the hashes are always recalculated
before
comparing them to the key or if the Dictionary is using a cached version.
I
don't suspect that is the case though.
Thanks for your input. We're trying to mockup a reproducible test case.
-Brian
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote
in
message news:uk**************@TK2MSFTNGP05.phx.gbl... Brian,
I'm inclined to believe that it doesn't do it, unless you are using
the Dictionary in an improper manner.
For example, are you performing operations on the dictionary from
other threads while enumerating through it?
Can you post a complete example which shows this happening?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Brian Richards" <br*******@gmail.com> wrote in message
news:eN**************@TK2MSFTNGP03.phx.gbl... > I'm experiencing some wierd behavior with a Dictionary<T,U> class using
> foreach loops, such that the Key returned in the foreach is not contained > in
> the dictionary.
>
> code:
>
> Dictionary<A, B> dict;
> ....
> foreach(A key in dict.Keys)
> {
> bool foo = dict.ContainsKey(A); //returning false
> }
>
> Does anyone know what kinds of circumstances could cause this?
>
>