CRR0053 - Missing 'await'
- 2 minutes to read
This analyzer identifies places where an async method should be awaited to avoid issues with exception handling and premature object disposal:
public Task<T> Handle(T request, CancellationToken cancellationToken) {
using var handler = HandlerFactory.CreateRequestHandler(request);
return ExecuteHandlerAsync<T>(handler, cancellationToken); // <-- CRR0053 reported for the ExecuteHandlerAsync(...) call
}
public Task<T> ExecuteHandlerAsync<T>(Handler<T> handler, CancellationToken cancellationToken) {
// A long running operation that utilizes handler object
}
To fix this warning, add the await
operator to the method call:
public async Task<T> Handle(T request, CancellationToken cancellationToken) {
using var handler = HandlerFactory.CreateRequestHandler(request);
return await ExecuteHandlerAsync<T>(handler, cancellationToken).ConfigureAwait(false); // <-- CRR0053 no longer reported for the ExecuteHandlerAsync(...) call
}
public Task<T> ExecuteHandlerAsync<T>(Handler<T> handler, CancellationToken cancellationToken) {
// A long running operation that utilizes handler object
}
See Also