I am developing a server in ASP NET Core 3.1 preview edition and now i see that for all my async
methods when calling await
i get CA2007
warning (as it is when some task is running asynchronous).
Is there any significant change in how the way async await works in .NET Core 3.1 that i am not aware of thus i should use ConfigureAwait
?
P.S If there is not change , is there any way for it to stop highlighting all await
's with green for which i am not using configureawait
?
You specify ASP.NET Core 3.1 in your question but not what version you're coming from. However, in ASP.NET Core (since the beginning?) you don't need to call ConfigureAwait(false)
from ASP.NET Core. See: ASP.NET Core SynchronizationContext by Stephen Cleary.
To stop the warning I put this in my GlobalSuppressions.cs
:
using System.Diagnostics.CodeAnalysis;
[assembly: SuppressMessage("Design", "RCS1090:Call 'ConfigureAwait(false)'.",
Justification = "ASP.NET Core doesn't have a SynchronizationContext. https://blog.stephencleary.com/2017/03/aspnetcore-synchronization-context.html",
Scope = "NamespaceAndDescendants",
Target = "YourProjectNamespace.Controllers")]
Note the Target = "YourProjectNamespace.Controllers"
. I try to be specific where I suppress the warnings. Since I can't control where my library code will be called from I want to ensure that my libraries still call ConfigureAwait(false)
. But in ASP.NET Core controllers I don't need to, thus the suppression.