简体   繁体   中英

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 ie 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?

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));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM