kontent-ai / delivery-sdk-net

Kontent.ai Delivery .NET SDK
https://www.nuget.org/packages/Kontent.Ai.Delivery
MIT License
32 stars 43 forks source link

Warning in AssetElementValueConverter #330

Closed Simply007 closed 2 years ago

Simply007 commented 2 years ago

Brief bug description

What went wrong?

AssetElementValueConverter.GetPropertyValueAsync is marked as async but does not use await.

Repro steps

  1. Clone the repository
  2. Build the solution see
C:\projects\kontent-delivery-sdk-net\Kentico.Kontent.Delivery\ContentItems\AssetElementValueConverter.cs(21,35): warning CS1998: This async method lacks 'await' operators and will run 
synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread. [C:\projects\kontent-delivery-sdk-net\Kentico.Kontent.Delivery\Kentico.Kontent.Delivery.csproj]
C:\projects\kontent-delivery-sdk-net\Kentico.Kontent.Delivery\ContentItems\AssetElementValueConverter.cs(21,35): warning CS1998: This async method lacks 'await' operators and will run 
synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread. [C:\projects\kontent-delivery-sdk-net\Kentico.Kontent.Delivery\Kentico.Kontent.Delivery.csproj]

Expected behavior

No warning

Context

Related to #318

MiroKentico commented 2 years ago

Hi @Simply007,

the problem is, that GetPropertyValueAsync uses naming convention for asynchronous methods. And in this AssetElementValueConverter case, it is really not a problem that it runs synchronously.

In linked PR this issue from warning is fixed by removal of async keyword and creating a new Task from the result. This solution is already used in NodaTimeValueConverterAttribute.