dotnet/roslyn

Misleading error for await in the watch window

Open

#46,795 opened on Aug 13, 2020

View on GitHub
 (0 comments) (0 reactions) (0 assignees)C# (20,414 stars) (4,257 forks)batch import
Area-InteractiveBughelp wanted

Description

Version Used: VS 16.7.1

Steps to Reproduce:

Attempt to use the await operator (e.g. await Task.Delay(0)) in the watch window while debugging a method.

Expected Behavior:

An error message explaining that the debugger doesn't support await, possibly suggesting to use .Result/.Wait() instead. Or even better, await works in the debugger.

Actual Behavior:

In the case of an async method, the error shown in the watch window is:

error CS4032: The 'await' operator can only be used within an async method. Consider marking this method with the 'async' modifier and changing its return type to 'Task<Task>'.

For a non-async method, the error is almost the same:

error CS4033: The 'await' operator can only be used within an async method. Consider marking this method with the 'async' modifier and changing its return type to 'Task'.

In both cases, the error is misleading: For the async method, it's already async and returns a Task, so the suggestion doesn't make sense. For the non-async method, adding async wouldn't fix the issue, so it's also wrong.

Contributor guide