Share via


C# Edit and Continue: error 4054 

Error Message

Modifying a 'method | property | indexer | operator' which contains the 'yield return' or 'yield break' statement will prevent the debug session from continuing while Edit and Continue is enabled

This error occurs if you try to modify a method, property, indexer, or operator containing a yield return or yield break statement. For more information, see yield (C# Reference). Edit and Continue does not support this change during debugging.

Consider the following code:

class Program

{

   private int[] items = { 1, 2, 3 };

   System.Collections.Generic.IEnumerable<int> Range(int start, int end)

   {

      for (int index = start; index < end; index++)

      {

      yield return items[index];

      }

   }

   static void Main()

   {

      Program p = new Program();

      foreach (int item in p.Range(0, 2))

      {

         

      }

   }

}

If you set a breakpoint on yield return items[index], then start debugging and try to add a local variable declaration int a = 10 in the Range method, this error occurs.

To correct this error

  • Undo the changes, and then continue debugging without the changes.

    —or—

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

See Also

Reference

yield (C# Reference)
Supported Code Changes (C#)
Edit and Continue (Visual C#)

Other Resources

Edit and Continue Errors and Warnings (C#)