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

System.NullReferenceException trying to return a null response #64

Closed
dday4thedeceiver opened this issue Aug 8, 2018 · 6 comments
Closed
Milestone

Comments

@dday4thedeceiver
Copy link

Trying to test the case when httpClient returns null:

var mockHttp = new MockHttpMessageHandler();
mockHttp.Fallback.Respond(() => Task.FromResult<HttpResponseMessage>(null));
var r = mockHttp.ToHttpClient().GetAsync("http://a").Result;

...throws a null reference exception.

@richardszalay
Copy link
Owner

Interesting. We definitely shouldn't be throwing a NRE, but under what situation would the actual HttpClient return null?

@dday4thedeceiver
Copy link
Author

I don't believe it does under Windows but I've seen reports on Android, it was more completeness/exploratory testing

@richardszalay
Copy link
Owner

No problem. I'll happy accept a PR (with tests!) if you're willing/able, otherwise I'll tackle it next time I make changes to the project.

@richardszalay richardszalay added this to the 6.0.0 milestone Feb 22, 2019
@richardszalay
Copy link
Owner

If you can provide a repro scenario where this actually happens on Android, making sure that it's not actually response.Content that's null, then I'm happy to add support myself.

@guibirow
Copy link

guibirow commented Nov 6, 2019

I don't think HttpResponseMessage can be null.

In general, it should return a response with the result for the request, to describe:

  • the response status code (if it was successful)
  • the content (That could probably be null in this case or an empty stream)

@richardszalay
Copy link
Owner

I'm going to close this issue. If you can find a real world scenario where this can happen I'm happy to add support

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

No branches or pull requests

3 participants