18

I am trying to debug a Linq expression in Visual Studio 2015. When I add it to the watch window I get the following error in the Value column.

field.DomainValues.Where(d => d.Active) error CS1061: 'List' does not contain a definition for 'Where' and no extension method 'Where' accepting a first argument of type 'List' could be found (are you missing a using directive or an assembly reference?)

When I try to execute in the Immediate Window I get the same error.

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

I thought that support was added for this in Visual STudio 2015 based on this article - http://blogs.msdn.com/b/visualstudioalm/archive/2014/11/12/support-for-debugging-lambda-expressions-with-visual-studio-2015.aspx

I found this article that outlines some limitations, but none apply to my x86 WPF application. http://dotnetdeewane.blogspot.com/2015/03/support-for-debugging-lambda.html

  • I have an x86 .Net 4.5 WPF app
  • In my output window I see that System.Core has been loaded.

Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll'

  • My method is static and not async. I do have the using System.Linq statement at the top of my class.

    using Infragistics.Windows.Editors;
    using Microsoft.Practices.ServiceLocation;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Windows;
    
    public static ValueEditor SelectEditor(ColumnConfig config, TableInfo info, object value = null)    
    {    
        //do some stuff    
        field.FilteredDomainValues = field.DomainValues.Where(d => d.Active).ToList();    
        //do some other stuff    
    }
    
  • I'm not using dynamic types

I have Visual Studio 2012 and Visual Studio 2013 also installed.

I am using Resharper.

Anything else I could check in VS options?

Darlene
  • 808
  • 5
  • 16

4 Answers4

3

The key is to ensure that System.Core.dll is loaded. One easy way to do this is to have the following at the top of the file you're debugging in:

#if DEBUG
using System.Diagnostics;
#endif
  • This is it. I had the same problem in a Unit-Test project. The above line fixed both the Watch as well as the Immediate Window. – t3chb0t Feb 22 '17 at 12:43
1

I had the same problem and i fixed it making a call to Enumerable.Range in the code before checking the lambda expression in the watching window

Ghini Antonio
  • 2,992
  • 2
  • 25
  • 48
  • Could you be a bit more specific. You added a Enumerable.Range call in your actual code just to facilitate the debugging? or you ran it in Immediate/Watch? – fahadash Mar 31 '16 at 14:43
  • Well, I tried that as well. And Watch/Immediate still complain about .Select(), .Where(), .Any() not being found – fahadash Mar 31 '16 at 15:16
1

According to MSDN:

NOTE: Lambda expressions that require native functions to run (e.g. LINQ-to-SQL) are not supported.

I see in your sample, that your method's parameters are of type TableInfo, ColumnConfig, which sound pretty SQL related to me. By any chance does field.DomainValues point to the DB and uses LINQ-To-SQL to be resolved?

slashCoder
  • 1,447
  • 21
  • 22
0

I use Debug > Windows > Immediate Window. It lets me type in expressions I use for debugging and experimenting. It comes with full Intellisense support

field.DomainValues
field.DomainValues.Where(d => d.Active)
field.DomainValues.Count(d => d.Active)
field.DomainValues.Where(d => d.Active).First()
Amadeusz Wieczorek
  • 3,139
  • 2
  • 28
  • 32
  • 1
    I see the same error when using the Immediate Window. I updated my original post to include that. – Darlene Aug 21 '15 at 16:18
  • What I have done in the past, is just .ToArray() my list (in the immediate window), and inspect from there. – Kevin Aug 21 '15 at 16:32