There don't appear to be rules that cover the safe usage of ValueTask<T>. These rules have recently been documented on the .NET Blog (there may be other locations).
See the linked blog post for details including code samples, but in summary code containing ValueTask<T> where the following operations are performed:
ValueTask / ValueTask<TResult> more than onceValueTask / ValueTask<TResult> concurrently.GetAwaiter().GetResult() when the operation may not have completedWarnings at appropriate levels.
No warnings.
None known.
Hi @alexangas,
Here is the rule we will implement based on the article you have provided: RSPEC-5034.
According to the docs "The use of the ValueTask
Thanks @andrei-epure-sonarsource and team!
The current implementation raises a False Positive on the following code:
if (!awaitable.IsCompleted)
{
return;
}聽
var readableBuffer = awaitable.GetAwaiter().GetResult().Buffer; // issue raised here
Nevermind. This is a True Positive. The code is not checking that the operation completed AND succeeded. Thus the call to awaitable.GetAwaiter().GetResult() will raise an exception if the operation failed.
Most helpful comment
Thanks @andrei-epure-sonarsource and team!