After upgrading from Visual Studio 2010 to 2012 code started throwing \"ArgumentOutOfRangeException - Index was out of range. Must be non-negative and less than the size of the
After giving this some more investigation, I've come to the conclusion that the problem is the anonymous class I'm returning from the Linq query, I think it isn't allowed anymore to return an anonymous class with only one field in it, I know it isn't needed to wrap the field in an anonymous class but ... as I said this worked before upgrading.
Following example gives me the "ArgumentOutOfRangeException - Index was out of range":
void Main()
{
var iq1 = ActionPlans.Select(ap => ap.ID).ToList();
var iq2 = iq1.Join(ActionPlans.Select(ap => ap.ID),
a => a,
b => b,
(a, b) => new { a });
iq2.Dump();
}
this next example works as expected:
void Main()
{
var iq1 = ActionPlans.Select(ap => ap.ID).ToList();
var iq2 = iq1.Join(ActionPlans.Select(ap => ap.ID),
a => a,
b => b,
(a, b) => a );
iq2.Dump();
}
Erwin, just to close the loop on this: We have confirmed that it is a bug we introduced recently in LINQ to Entities and we are looking at ways to get a fix out. Thanks a lot for reporting it!