I have the following extension method for Dictionary collection
public static IEnumerable<Dictionary<TKey, TValue>> Split<TKey, TValue>(
this Dictionary<TKey, TValue> array,
int size)
{
for (var i = 0; i < (float)array.Count / size; i++)
{
yield return array.Skip(i * size)
.Take(size)
.Select(t => new { t.Key, t.Value })
.ToDictionary(t => t.Key, t => t.Value);
}
}
And I'm using it like this:
var batches = ItemsDictionary.APIitems.Split(20).ToList();
ItemsDictionary.APIitems gets initialized in another method and always not null and not empty when I call Split() extension method. It works just fine, but in 50% of executions it throws
System.ArgumentNullException at Extentions.DictionaryExtentions+<Split>d__0``2.MoveNext
Any ideas what could be the cause of ArgumentNullException?