dotnet/roslyn

Misleading error for await in the watch window

開放

#46,795 建立於 2020年8月13日

 (0 則留言) (0 個反應) (0 位負責人)C# (4,257 個分叉)batch import
Area-InteractiveBughelp wanted

倉庫指標

星標
 (20,414 顆星)
PR 合併指標
 (平均合併 6天 17小時) (30 天內合併 256 個 PR)

描述

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.

貢獻者指南