dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
18.96k stars 4.03k forks source link

Edit and Continue debugger bug with async Task Main in VS 2017 #32224

Open ivanbasov opened 5 years ago

ivanbasov commented 5 years ago

copies from https://github.com/dotnet/corefx/issues/31241

The debugger does not display values correctly after "Edit and Continue" when called directly within async Task Main.

In each example there are 2 lines of code commented out. While executing a particular snippet, debug up to var x = 5 and then uncomment the commented lines, save, and proceed to step over. In the "Examples that fail", after editing and continuing and stepping over y, it will appear as 0, and if you click the "evaluate now" button in the local or watch windows, you will receive the error, The debugger is unable to evaluate this expression. I included the Console.WriteLine to demonstrate that the value is still correctly printed to console, it's just not viewable while debugging.

Examples that work:

//works static Task Main(string[] args) { var x = 5; //var y = 6; //Console.WriteLine(y); return Task.FromResult(0); }

//works static async Task Main(string[] args) { await Task.Yield(); Helper();

void Helper()
{
    var x = 5;
    //var y = 6;
    //Console.WriteLine(y);
}

} Examples that fail:

//fails static async Task Main(string[] args) { var x = 5; //var y = 6; //Console.WriteLine(y); }

//fails static async Task Main(string[] args) { await Task.Yield(); var x = 5; //var y = 6; //Console.WriteLine(y); }

ivanbasov commented 5 years ago

Discussed with @tmat:

  1. The problem can be on CoreClr, on EE or on Roslyn.
  2. Investigations can take a lot of time and are not easy.