When I run FxCop on my project, I get a large number of warnings with the ID of CA2007. This ID is missing from the docs (it just skips from CA2006 to CA2100), but the message I get is:
Do not directly await a Task without calling ConfigureAwait
I was under the impression that .NET Core didn't use synchronisation contexts and that this meant I didn't need to use .ConfigureAwait(bool)
. When I try and Google it though, I can now only find mentions of ASP.NET Core (e.g. this blog post).
Given that I can't find anything authoritative, I'm beginning to wonder whether I've mistaken an ASP.NET Core change for one that applies more generally to all of .NET Core.
Can anyone give me a definitive answer?
Should I need to go through my app and apply a liberal sprinkling of ConfigureAwait
? Or should I just disable CA2007 in my FxCop ruleset?
Yes in some situations. If your code is ever used as a library or someone introduces a SynchronizationContext. refer to this article. https://devblogs.microsoft.com/dotnet/configureawait-faq/#ive-heard-configureawaitfalse-is-no-longer-necessary-in-net-core-true