Support for debugging lambda expressions with Visual Studio 2015

Anyone who uses LINQ (or lambdas in general) and the debugger will quickly discover the dreaded message “Expression cannot contain lambda expressions”. Lack of lambda support has been a limitation of the Visual Studio Debugger ever since Lambdas were added to C# and Visual Basic. We’ve heard your feedback and we are pleased to announce that the debugger now supports evaluation of lambda expressions!

Let’s first look at an example, and then I’ll walk you through current limitations.

Example

image

To try this yourself, create a new C# Console app with this code:

using System.Diagnostics;
using System.Linq;

class Program
{
    static void Main()
    {
        float[] values = Enumerable.Range(0, 100).Select(i => (float)i / 10).ToArray();

        Debugger.Break();
    }
}

Then compile, start debugging, and add “values.Where(v => (int)v == 3).ToArray()” in the Watch window. You’ll be happy to see the same as what the screenshot above shows you.

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

Summary

Please let us know how it works for you and what we can do to improve the experience below through the Send a Smile feature in Visual Studio or via twitter