How to continue debugging after editing a method containing a lambda expression?

Usually, when a method contains a lambda expression in it, if you edit this method, Visual Studio will say:

Modifying the "method" that contains the lambda expression will prevent the debugging session from continuing while editing and continuing are allowed.

Is there any way to avoid this error?

In my case, I have a class whose constructor accepts Action .

 Button(Texture2D t2d, Vector2 v2, Action onPress) ... Button b = new Button(t2d, new Vector2(40, 60), () => { MainStatic.t = t; }); 

Additional information on this issue:

+4
source share
1 answer

UPDATE: The desired function was added in Visual Studio 2015 after many user requests for this function. This answer and question is now out of date.


Is there any way to avoid this error?

Yes. Remove the lambda from the method. Or do not edit the method.

Is there a way to avoid this error by not removing the lambda from the method and still editing the method?

No. The error message does not apply to you.

The reason for this, if you're interested, is that lambdas are compiled as methods of a nested class, and local variables that are closed by lambdas become fields of this class. The edit-and-continue function overwrites the current method on the fly when you edit it, but even simple changes can lead to complex changes for these nested classes. Instead of spending a lot of effort in making the E&C work for this scenario, and thus stealing resources from other, more valuable functions, the debugger team simply made it illegal.

+10
source

All Articles