Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

c# 6 null-conditional operator doesn't work for await statement #7556

Closed
Misterhex opened this issue Dec 17, 2015 · 4 comments
Closed

c# 6 null-conditional operator doesn't work for await statement #7556

Misterhex opened this issue Dec 17, 2015 · 4 comments
Labels

Comments

@Misterhex
Copy link

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?

@Misterhex Misterhex changed the title c# 6 await request.Content?.ReadAsStringAsync() doesn't work c# 6 null-conditional operator doesn't work for await statement Dec 17, 2015
@ufcpp
Copy link
Contributor

ufcpp commented Dec 17, 2015

#7171

@gafter
Copy link
Member

gafter commented Dec 17, 2015

Yes, it is intentional behavior that awaiting null results in a null reference exception.

@Mardoxx
Copy link

Mardoxx commented Aug 15, 2017

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...

@CyrusNajmabadi
Copy link
Member

Proposal on a language change to address htis is here: dotnet/csharplang#35

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants