Ir al contenido

ValueTask consumed incorrectly (CA2012)

Esta página aún no está disponible en tu idioma.

Key dotnet.async.valuetask-misuse · Severity error · Category async

Microsoft analyzer CA2012. Flags a ValueTask awaited twice, stored and awaited later, or read with .Result before it completes. A ValueTask may wrap a pooled object that is reused after the first await.

ValueTask<int> pending = reader.ReadAsync(buffer);
var first = await pending;
var again = await pending;
var read = await reader.ReadAsync(buffer);
// need it twice? keep the result, or call .AsTask() once