Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linq Extension Methods Not available in Visual Studio 2015 Immediate Window

error CS1061: 'ICollection<>' does not contain a definition for 'SelectMany' and no extension method 'SelectMany' accepting a first argument of type 'ICollection<>' could be found (are you missing a using directive or an assembly reference?)

Visual Studio 2015 supports evaluating linq lambda expressions in debug mode, in immediate window. I have tested it with a console application wherein i fetch Process.GetProcesses(), go to immediate window and start writing .Select or .Where on it. It works fine.

However, I am not able to do the same in my Project.

My Breakpoint is at this line:

return Dimensions.Values.SelectMany(dimension => dimension.Attributes)
                        .FirstOrDefault(dimensionAttribute => key.Equals(dimensionAttribute.Key));

Doing a F10 works. However when I try to run this same expression in parts, in immediate window i.e. Dimensions.Values.SelectMany(dimension => dimension.Attributes), I get the above mentioned error.

Am I trying to evaluate this in an incorrect manner? What am I missing?

like image 646
singsuyash Avatar asked Nov 20 '22 15:11

singsuyash


1 Answers

I can't give you the reason why that happens (I have similar issues with the Immediate Window), but I found that you can call extension methods via static class access. In your case that would be:

Enumerable.FirstOrDefault(Enumerable.SelectMany(Dimensions.Values, dimension => dimension.Attributes),dimensionAttribute => key.Equals(dimensionAttribute.Key));
like image 154
Lennart Avatar answered Nov 22 '22 06:11

Lennart