Jon Gallant

Solution: CS1061: 'AsyncPageable<GenericResourceExpanded>' does not contain a definition for 'GetAwaiter'

1 min read

I’ve been coding in .NET for a very-long-time, but this tripped me up.

Run the following code:

var resources = await client.Resources.ListByResourceGroupAsync(resourceGroupName);
foreach (var resource in resources)
{
Console.WriteLine(resource.Name);
}
```text
And you get this:
```bash
error CS1061: 'AsyncPageable<GenericResourceExpanded>' does not contain a definition for 'GetAwaiter'
and no accessible extension method 'GetAwaiter' accepting a first argument of type 'AsyncPageable<GenericResourceExpanded>' could be found
(are you missing a using directive or an assembly reference?)
```text
I thought I was doing everything right, awaiting anAsyncmethod. But it turns out with `IAsyncEnumerable` you `await` the result of the call like so:
```csharp
var resources = client.Resources.ListByResourceGroupAsync(resourceGroupName);
await foreach (var resource in resources)
{
Console.WriteLine(resource.Name);
}

Notice the await foreach?

I hope that helps. Jon

Share:
Share on X