Protector one
Protector one

Reputation: 7271

"Debugging lambda expressions with Visual Studio" no longer working?

In Visual Studio 2015, support for debugging lambda expressions was introduced: https://devblogs.microsoft.com/devops/support-for-debugging-lambda-expressions-with-visual-studio-2015/

However, I've never been able to get this to work in Visual Studio 2017, nor in the new Visual Studio 2019.

In 2019, I get: "Error: Inspecting the state of an object in the debuggee of type System.Reflection.PropertyInfo is not supported in this context".

Did this functionality get removed?

 
Example: I am debugging code with a variable "tags" that contains an IQueryable. I want to check the Name property of every item, so in the Immediate Window or Watch window I write: tags.Select(t => t.Name). Then the error.

Upvotes: 7

Views: 4693

Answers (3)

Manotosh Roy
Manotosh Roy

Reputation: 11

As an alternative, you can use an Immediate window to explore the value. Consider the simple code here:

static void Main(string[] args)
{
   int[] Numbers = { 10, 20, 30, 40 };

   var NewNumbers = Numbers.Select(x => x * x);
}

Put a debug point where your lambda expression is and open the Debug -> Window -> Immediate.

In the Immediate window, you can write the expression you want to test and see the result. I typed:

Numbers.Select(x => x*x)

Press enter, you will see the result as :

Count = 4
    [0]: 100
    [1]: 400
    [2]: 900
    [3]: 1600

An Immediate window is a playground to check variables, run expressions, and helps to debug faster.

Upvotes: 1

Protector one
Protector one

Reputation: 7271

This is more of a temporary answer without background until someone with knowledge comes along.

If you call ToArray on the IQueryable, you can use lambdas in debugging on that. It doesn't work on the AsEnumerable result though, so it doesn't simply seem to be about using IEnumerable methods vs. IQueryable methods.

Upvotes: 1

Ravi
Ravi

Reputation: 1172

This was caused by a missing feature in the new debug engine Microsoft had introduced, apparently. Following instructions from this link I got things to work. The instructions boil down to:

  1. From the "Tools" menu open "Options".
  2. On the left hand side pick "Debugging", "General".
  3. Scroll all the way down to check "Use Managed Compatibility Mode".

Upvotes: -1

Related Questions