Skip to main content

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

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

async Task<string> DemoMethodAsync(CancellationToken token) {
    await DoThings();
    return await Task.FromResult("Success");
}

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

async Task<string> DemoMethodAsync(CancellationToken token) {
    await DoThings();
    return "Success";
}