Eshoponcontainers: [Question] Warning CA2007: Do not directly await a Task without calling ConfigureAwait

Created on 19 Feb 2018  路  6Comments  路  Source: dotnet-architecture/eShopOnContainers

Hi,

I have been watching the repository and i got some doubts in how the tasks work in netcore. I have installed the nuget Microsoft.CodeAnalysis.FxCopAnalyzers to see what should appear in the eShopOnContainers solution.

I got almost everywhere the warning CA2007. Should i remove all the async / await, and use only one ConfigureAwait(false) in the first call? What shold be the best implementation for this scenario?

Most helpful comment

It doesn't seem to be relevant anymore in ASP.NET Core since the way context was working in ASP.NET has changed in ASP.NET Core. The Analyzer is wrong.
Sources:

Solution:
Consider deactivating this rule of the analyzer.
I personally add CA2007 in the Project "Property >Build > Suppress Warnings" field from VS.

All 6 comments

I have exactly the same question!

Hi @eddynaka, @rliberoff, although this it is a bit old, I installed the latest Microsoft Code Analysis VSIX (that uses analyzers v2.6.0), as per https://github.com/dotnet/roslyn-analyzers and rebuilt the eShopOnContainers-ServicesAndWebApps solution but didn't get any warning, could you please confirm this warning is still showing and, if so, how did you do to get it, because I might be missing something.

TIA

Closing this issue as could not reproduce it and it's not directly related to an issue with the application.

FWIW, I am using Microsoft.CodeQuality.Analyzers 2.6.3 (the nuget package, not VSIX), and I get this warning in my .NET Core 2.1 projects

It doesn't seem to be relevant anymore in ASP.NET Core since the way context was working in ASP.NET has changed in ASP.NET Core. The Analyzer is wrong.
Sources:

Solution:
Consider deactivating this rule of the analyzer.
I personally add CA2007 in the Project "Property >Build > Suppress Warnings" field from VS.

Thanks for the clarification @JulienBara.

I got to understand this a bit better recently.

As I understand now, the ConfigureAwait(false) is recommended for libraries, so that when the awaited task completes, the result is not delivered in the same thread (synchronized) that created the task, because that's costly and it's only needed for UI and ASP.NET (not Core) and hence it should not be a responsibility of a library.

However, .NET Core doesn't have the SyncronizationContext class that was used for that synchronization, so it's basically useless in .NET Core,

ConfigureAwait(false) has a place for .NET Standard libraries, because they can be used in .NET Framework applications, where this could be an issue, but definitely it's not the case in eShopOnContainers.

Hope this helps.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bakbuz picture bakbuz  路  4Comments

Diggzinc picture Diggzinc  路  5Comments

nxtx picture nxtx  路  4Comments

dgaspar picture dgaspar  路  4Comments

Dudelsb picture Dudelsb  路  3Comments