GurdeepS
GurdeepS

Reputation: 67223

Stepping through Linq statement tips

When I step through code and get to a linq statement, the stepping through process and the lines which are evaluated (and their order) are not the same as the code is written. I know this is to do with commands like yield etc.

My questions are:

  1. What do I need to learn to understand why the code is debugged in the way it is (with Linq statements)?
  2. What stepping through techniques are there for Linq statements?

Oh, and I use Visual Studio 2010 Ultimate.

Upvotes: 7

Views: 1954

Answers (2)

Haris Hasan
Haris Hasan

Reputation: 30097

According to MSDN

Any query that compiles to an expression tree produces code that is beyond the control of the debugger.

So you won't be able to fully debug the Linq query through Visual Studio Debugger.

But

there are few tool which can help for example Linq Pad

This page also describes some techniques that can be used for debugging Linq statements

This is another detailed article about debugging Linq

Upvotes: 2

Tigran
Tigran

Reputation: 62246

I'm not aware of any other method of debugging of the generated IL code, then using Sos, on your binary. You can do everything (if not more) of then you're able to do in VS debugging tools (may be a multithreading debugging stuff is better to do in VS). But again, considering the LINQ code is not the code you see in your codefile, but the IL code generated at compile time, I would say, that, by me, this is the only possible way to make StepInto/Over/Out on code like that.

Upvotes: 0

Related Questions