Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't you edit and continue debugging when there's a Lambda expression in the method?

I've seen it said in other questions that the Linq query syntax compiles to a Lambda.

So why can you not do edit-and-continue when there is a Lambda expression in the method, while with query notation you can?

What's most infuriating, and is seriously making me consider switching to using query notation everywhere, is that even if your code is not in the Lambda, but there's a Lambda somewhere else in the same method, you can't edit-and-continue! That's, like, gratuitous pain inflicted upon unwary developers!

like image 514
Shaul Behr Avatar asked Aug 19 '09 13:08

Shaul Behr


People also ask

Can I change code while debugging?

If selected, Visual Studio automatically compiles and applies code changes when you continue debugging from a break state. Otherwise, you can choose to apply changes using Debug > Apply Code Changes.


1 Answers

Edit and continue is able to change method implementations "live", but not what fields are in types.

Lambda expressions (and anonymous methods) can end up creating their own private types when they capture variables. Changing the lambda expression can change the types involved, which would break edit and continue.

It sounds like it should be possible to make changes to the code which don't have this impact, but I suspect it's simply easier to prevent it entirely - which also means you don't start making changes and then find that you're prevented half way through your change.

(Personally I'm not a fan of E&C in the first place, so I've never noticed it.)

like image 177
Jon Skeet Avatar answered Sep 28 '22 04:09

Jon Skeet