A portion of my code involving an async
Lambda function is failing. Here is the snippet:
var uniqueNotes = (await _api.GetContactAssocData(contactId))?
.Results?
.Select(async r =>
{
var noteDetail = await _api.GetNoteDetails(r.ToObjectId);
return $"{noteDetail?.Properties?.Timestamp}|{noteDetail?.Properties?.NoteBody}";
}).ToHashSet();
I have anonymized the method/variable names to protect my employer's IP.
The error given by the compiler is Cannot implicitly convert type 'System.Collections.Generic.HashSet<System.Threading.Tasks.Task<string>>' to 'System.Generics.HashSet<string>'
This error message would make total sense if I were failing to await
the Task
inside the statement block. But as you can see, I appear to have everything correctly in place for my statement to return: there is an async
at the start of the Lambda, and the method call inside my block is await
ed before assigning its properties to the string that is returned by the block.
Thus, it seems this block would return an IEnumerable
of string
s rather than of Task<string>
s, since each Task
generated by the Select()
is (theoretically) being await
ed before being evaluated.
Do you have any idea what I might be doing wrong?