.NET EnC support for Lambdas and other improvements in Visual Studio 2015

Hopefully you saw our previous post covering newly supported edit types added in our previous CTP of Visual Studio 2015 (if not, I’d recommend looking at that post first). Now, we are pleased to announce that Visual Studio 2015 RC contains even further Edit and Continue (Enc) improvements when debugging .NET applications.

New Edit and Continue functionality

Visual Studio 2015 RC adds the ability to:

  • Create and edit lambda expressions—For more details on this top UserVoice ask I recommend reading the blog post written by the .NET team covering 2015 RC improvements
  • Edit and Continue while remote debugging—this will just work when launching applications under the debugger, if you want to use it when attaching see the information below on how to edit and continue on attach.
  • Edit and Continue when debugging on Windows Phone 10 emulators—does not work on ARM devices
  • Edit and Continue on attach—to enable edit and continue on attach, you must set the environment variable COMPLUS_FORCEENC=1 so it is present when the process is started (see below section for further details and restrictions).

Note: Edit and Continue does not work for ASP.NET 5 applications at this point in Visual Studio 2015, but it is something we are working on and will ship as soon as it’s ready.

A few notes about attach

The reason you can’t just attach and then perform an Edit and Continue is that in order to support EnC the .NET runtime allocates extra memory up front that it will use to place the updated code in. This has a small effect on the performance and memory of the process so the runtime normally only retains this information if the process launched by the debugger. In the absence of a debugger being attached a process creation, if the runtime sees the environment variable COMPLUS_FORCEENC=1, it will reserve the extra memory to make edit and continue possible at a future point in time.

There are also a few limitations to be aware of in the context of attach:

  • You must have the Visual Studio project open that corresponds to the running application since Visual Studio needs to build the project to apply the edits.You cannot edit and continue inside of modules that are compiled Release. This is because modules compiled Release often contain optimizations (e.g. inlining of other method calls) that make it too difficult for the compiler to know how to compile the edits.
  • If you make an edit after attaching you cannot detach the debugger; the debugger will terminate the process when you stop debugging. This due to the fact that once you make an edit, the updated debug information is only available in the debugger’s memory which is lost when you stop debugging, so rather than leaving the process in a state that it can never be debugged again the debugger terminates it.
  • Setting this environment variable inside of IIS will not enable EnC when debugging inside of IIS due to a limitation in the debugger for 2015 RC. We will be resolving this before we ship the final version of Visual Studio 2015 (which of course we’ll tell you about here on the diagnostics blog).

If you have any questions or comments, please let me know below, through Visual Studio’s Send a Smile feature or in our MSDN forum.

11