I am getting an IndexOutOfRange exception while adding values to Generic dictionary (WinRT C#). Below is my code and stack trace of exception.
Code:
if (!data.TryGetValue(index, out cells))
{
cells = new CellCollection();
data.Add(index, cells);
}
Stack trace:
at System.Collections.Generic.Dictionary
2.Insert(TKey key, TValue value, Boolean add) at System.Collections.Generic.Dictionary
2.Add(TKey key, TValue value)
I wouldn't expect this out of range exception occurs while adding. My application uses single thread only. I have add values to dictionary and remove it from dictionary using GC.Collect() if not needed. And then add the value if needed.
Can anyone give any suggestion to resolve this exception?
.AsParallel()
ofParallel.ForEach
or something. However, can we see whatTKey
, i.e. the type ofindex
is? – Jeppe Stig Nielsen