Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Watch Linq Expressions in VS 2015

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?

like image 888
Darlene Avatar asked Aug 21 '15 15:08

Darlene


People also ask

How to debug LINQ queries in Visual Studio?

You can use the debugger windows to see whether each item meets the specified condition, and you can step through the code in IsEven . The predicate in this example is fairly simple. However, if you have a more difficult predicate you have to debug, this technique can be very useful.

How do I quick watch in Visual Studio?

It's available from Debug | Windows | Watch | Watch 1 or Ctrl + Alt + W + 1. There are 4 watch windows in Visual Studio, which you can use in different contexts (Watch 1, Watch 2, etc.). Any expression can be entered into the watch window.

Where is immediate window in Visual Studio?

On the Debug menu, choose Windows > Immediate.

What are Linq expressions?

Language-Integrated Query (LINQ) is the name for a set of technologies based on the integration of query capabilities directly into the C# language. Traditionally, queries against data are expressed as simple strings without type checking at compile time or IntelliSense support.


2 Answers

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
like image 92
Daniel Walton Avatar answered Oct 14 '22 05:10

Daniel Walton


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

like image 27
Ghini Antonio Avatar answered Oct 14 '22 04:10

Ghini Antonio