var body = await request.Content?.ReadAsStringAsync();
throw an nullreferenceexception when when request.Content is null instead of just returning null.
Is this an intended behaviour?
Yes, it is intentional behavior that awaiting null results in a null reference exception.
Yes, it is intentional behavior that awaiting null results in a null reference exception.
That sucks.
I wanted to do something like this using the MS Graph SDK:
var graphClient = new GraphServiceClient(authProvider);
var users = await graphClient.Users.Request().GetAsync();
do
{
foreach (var user in users)
{
Console.WriteLine($"{user.Id} : {user.GivenName} {user.Surname}");
}
}
while ((users = await users.NextPageRequest?.GetAsync()) != null);
I guess
while (users.NextPageRequest != null && (users = await users.NextPageRequest.GetAsync()).Count > 0);
isn't that bad...
Proposal on a language change to address htis is here: https://github.com/dotnet/csharplang/issues/35
Most helpful comment
Proposal on a language change to address htis is here: https://github.com/dotnet/csharplang/issues/35