Back to Devexpress

CRR0036 - The 'await Task.FromResult()' expression is redundant

coderushforroslyn-119691-static-code-analysis-analyzers-library-crr0036-the-await-task-from-result-expression-is-redundant.md

latest1.2 KB
Original Source

CRR0036 - The 'await Task.FromResult()' expression is redundant

  • Feb 28, 2025

This analyzer detects statements with the await keyword that constructs a task from a literal and waits until it returns the result.

csharp
async Task<string> DemoMethodAsync(CancellationToken token) {
    await DoThings();
    return await Task.FromResult("Success");
}
vb
Async Function DemoMethodAsync(token As CancellationToken) As Task(Of String)
    Await DoThings()
    Return Await Task.FromResult("Success")
End Function

Such statements are redundant because they always evaluate to the passed literal and may be replaced with the literal itself.

csharp
async Task<string> DemoMethodAsync(CancellationToken token) {
    await DoThings();
    return "Success";
}
vb
Async Function DemoMethodAsync(token As CancellationToken) As Task(Of String)
    Await DoThings()
    Return "Success"
End Function

See Also

Suppress Analyzers