Visual Studio Debugging "Quick Watch" Tool and Lambda Expressions

Visual Studio debugging quick watch tool and lambda expressions

Lambda expressions, like anonymous methods, are actually very complex beasts. Even if we rule out Expression (.NET 3.5), that still leaves a lot of complexity, not least being captured variables, which fundamentally re-structure the code that uses them (what you think of as variables become fields on compiler-generated classes), with a bit of smoke and mirrors.

As such, I'm not in the least surprised that you can't use them idly - there is a lot of compiler work (and type generation behind the scenes) that supports this magic.

How to watch (i.e. debug) extra-lambda variable inside lambda scope in C#/Visual-Studio/Unity3d?

Turns out this is a variation of C# lambda call in for loop references to last object

There is an issue with Mono/Unity with coroutines and lambda expressions;

The coroutine itself is an implicit closure as well which moves all local variable to a seperate class as member variables. That means it's impossible to create a "real" local variable inside a generator method. That's why the explicit local variable declaration doesn't work.

See http://answers.unity3d.com/questions/974036/c-lambda-call-in-for-loop-references-to-last-objec.html

lambda expressions in immediate window for VS2015

This definitely works for me, looks like when I tick either Use Managed Compatibility Mode or Use the legacy C# and VB expression evaluators it stops working. Ensure those are unchecked.

Sample Image

Why can't I use lambda expressions in the Immediate Window?

Jaredpar explained it

Why is LINQ absent from debugger windows?

Why is LINQ absent from debugger windows (Part 2)?

How to debug a Linq Lambda Expression?

You can't debug a Lambda expression if you're using a Linq to Entities provider.

But you can take a look at what SQL it translate into.
Also if you are willing to suffer a performance hit - you could load it all into Linq to obejcts - and do a Step by step



Related Topics



Leave a reply



Submit