Partager via


C# Edit and Continue: error 4027 

Error Message

Updating a block statement around an active statement will prevent the debug session from continuing while Edit and Continue is enabled

This error occurs if:

  • You try to modify part of a foreach statement, a using statement, a lock statement, or a fixed statement, when the execution pointer is inside the modified block.

  • You try to add a catch to a try when the execution pointer is inside the modified block.

  • You try to change a try/catch to a try/finally when the execution pointer is inside the modified block.

For more information, see Active Statements.

Consider the following code:

class Program

{

   static void Main()

   {

      using (System.IO.StreamReader file = System.IO.File.OpenText(@"example.txt"))

      {

         System.Console.WriteLine(file.ReadLine());

      }

   }

}

If you set a breakpoint on the WriteLine call and start debugging, then try to change the name of the text file in the using statement, this error occurs.

To correct this error

  • Choose Undo from the Debug menu to undo the changes. You can make the change later when the statement is no longer active.

    –or–

  • On the Debug menu, click Stop Debugging, then make your changes and start a new debugging session.

See Also

Reference

foreach, in (C# Reference)
using (C# Reference)
try-catch (C# Reference)
try-finally (C# Reference)
lock Statement (C# Reference)
Supported Code Changes (C#)
Edit and Continue (Visual C#)

Other Resources

Edit and Continue Errors and Warnings (C#)