IndexOutOfRange error with Dictionary in C#

This happens when you are adding data to the Dictionary<TKey, TValue> from multiple threads, the underlying implementation is using arrays.

To solve, switch to use ConcurrentDictionary, and use GetOrAdd.