ArgumentOutOfRange exception when using Count() and ElementAt(), First() #190

Closed
nikoladj13 opened this Issue Apr 22, 2013 · 1 comment

Comments

Projects
None yet
2 participants

Hi all,

I am new to Massive. Tried to implement it and in general it works fine. However, occasionally i face a strange problem with ElementAt and First methods. Here is the code sample:

var calcualtionRows = tableCalculation.All();                 
if (calcualtionRows.Count() == 0)
    return;
var calculationId = calcualtionRows.ElementAt(0).id; //here it crash with the following exception:

Source: System.Core;
Target site: TSource ElementAt[TSource (System.Collections.Generic.IEnumerable1[TSource], Int32); Message: Specified argument was out of the range of valid values. Parameter name: index; StackTrace: at System.Linq.Enumerable.ElementAt[TSource](IEnumerable1 source, Int32 index)

Very similar message i get with First method instead of ElementAt.

Basically, i face this problem once per 10-20 runs. Any idea would be appreciated.

Thanks

Contributor

robconery commented Apr 24, 2013

Best to ask this on StackOverflow - this isn't an issue with Massive. But, to answer your question this is because you're asking for an element at position 0 and there isn't one. What you want to use is FirstOrDefault().

@robconery robconery closed this Apr 24, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment