Wednesday, September 26, 2007

C#: NULL key in Dictionary<>

Few days ago I got an exception while enumerating a Dictionary<>. It was a null pointer exception for a key object. Since the keys in a dictionary may not be null I've started to dig and found the reason - multi threading writers to a dictionary without locks can cause null key (even if the writing was before the enumeration).

Solution: locks.

2 comments:

Erraticly Composed said...

Thanks, you've saved me a whole lot of trouble trying to figure out what went wrong...

Casiel said...

Thank you very much!!!! You saved me a lot of research time too.

Regards,

JMP