Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Editing code in Visual Studio 2008 in debug mode

I am curious to know if there is a way to edit code in C# VS 2008 right when it has hit a breakpoint and I am walking thru the code... can I modify the code (such as the value in a variable or if my stepthrough line is about to hit an if statement ... can I modify the if statement....etc)? So far, I have to stop running VS, modify the code, then hit F5 and wait till the breakpoint is hit again.

When the breakpoint hits, and I am walking thru the code, and I attempt to edit the code, I get a message "Changes are not allowed when the debugger has been attached to an already running process of the code being debugged was optimized at build or run time."

like image 757
user279521 Avatar asked May 06 '10 12:05

user279521


People also ask

How do you run code in debug mode in VS code?

To bring up the Run and Debug view, select the Run and Debug icon in the Activity Bar on the side of VS Code. You can also use the keyboard shortcut Ctrl+Shift+D. The Run and Debug view displays all information related to running and debugging and has a top bar with debugging commands and configuration settings.


2 Answers

There are only a few reasons I know of why Edit+Continue would be disabled in the Debug build. First and foremost is a 64-bit operating system, E+C only works for 32-bit code. Fix that with Project + Properties, Build tab, Platform Target = x86.

It is also an option that might have been turned off. Tools + Options, Debugging, Edit and Continue, Enable checkbox.

If this doesn't help, tell us a bit more about the kind of code you're debugging, the project template you selected when you started the project, how you got the debugger to break and a stack trace copied from the Call Stack window.

like image 174
Hans Passant Avatar answered Sep 30 '22 15:09

Hans Passant


Yes, you can.
This is called Edit and Continue.
Note that it has some limitations.

EDIT: You need to switch to a debug build.

like image 35
SLaks Avatar answered Sep 30 '22 13:09

SLaks