I am trying to use the LINQ function IEnumerable.Aggregate to create a string consisting of files received through asynchronous calls. Not one hundred percent sure that this is possible, and I also know that there are other solutions, but I would like to try.
Now my code is as follows:
private static async Task<string> GetFiles(IEnumerable<string> filePaths)
{
return filePaths.Aggregate(async (current, path) => current + await GetFile(path));
}
But the "asynchronous" inside the method call is marked with an error saying: "the return of the asynchronization method must be invalid, task or task." I get this error at all, but I'm not sure how to organize this particular case to avoid this. Any ideas?
UPDATE: To just clarify, the GetFile () method is really asynchronous and returns Task<string>:
private static async Task<string> GetFile(string filePath) { ... }
No need to go into specific code, but for those who are interested, it uses HttpClient.GetAsync(filePath)and returns it response.Content.ReadAsStringAsync().Result.
source
share