C# Edit and Continue: error 4001

Editing or deleting an active statement which is being executed will prevent the debug session from continuing while Edit and Continue is enabled

This error indicates that you tried to edit or delete the active statement, the statement where the execution pointer is located. Edit and Continue does not support changes to the active statement while debugging.

The most common cause of this message is stepping out of a function back to the call site. The debugger returns to the invocation of the method but has not yet stepped to the next statement. Until it does so, the line that called the method cannot be edited. If you try to edit it, you will receive this message.

For example, consider the following code:

class Program

{

   static void Example()

   {

      System.Console.WriteLine("Example");

   }

   static void Main()

   {

      Example();

      int a = 5;

   }

}

If you set a breakpoint on the Console.WriteLine call, then start to debug the application and step out of the Example method, the instruction pointer is still in Example, so the call cannot be edited.

To correct this error

  • Choose Undo from the Debug menu to undo the change, then step until the statement you want to edit is no longer active or use Set Next Statement to move the instruction pointer.

    -or-

  • Stop the debugging session, make your edits, and start a new debugging session.

See Also

Reference

Supported Code Changes (C#)

Edit and Continue (Visual C#)

Other Resources

Edit and Continue Errors and Warnings (C#)