I'm at a loss. I have a Dictionary object with String keys. The objects are of a custom type I have. This example throws an InvalidCastException:
MyObject temp;
if(Dict.TryGetValue("abc", out temp)) //exception
If I instead use "ContainsKey", I still get an InvalidCastException:
if(Dict.ContainsKey("abc")) //exception
In both cases, if I put a watch on Dict["abc"], I get the value that I want from the Dictionary. The Exception details provide no extra information.
I tried putting together a small code sample that replicates this situation, but my code samples work perfectly. I don't know how to provide a code sample for this problem.
Why would I get an InvalidCastException when checking for the existence of a key in a Dictionary? Why does ContainsKey even need to do any casting in its implementation? How do I fix this?