Partager via


C# Edit and Continue: error 4065 

Error Message

Constructor cannot be modified while debugging because field <field name> has an initializer using an anonymous method

You tried to modify a constructor that contains a field initialized by an anonymous method. Edit and Continue does not support this change during debugging.

Consider the following code:

class Example

{

   private System.EventHandler Click = delegate

      { System.Console.WriteLine("Hello"); };

    public Example()

   {

   }

   static void Main(string[] args)

   {

   }

}

If you step into the application, then try to add int a = 10 in the constructor, this error occurs.

To correct this error

  • On the Edit menu, click Undo to undo the changes

    -or-

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

See Also

Reference

Anonymous Methods (C# Programming Guide)
Supported Code Changes (C#)
Edit and Continue (Visual C#)

Other Resources

Edit and Continue Errors and Warnings (C#)