Skip to content

NullReferenceException if returned Content is null and success status code #60

@dpakpaul

Description

@dpakpaul

Using the latest 3.0.1 version of Portable Rest.

When I call SendAsync() that does a PUT request, I get back a 400 Bad Request by the Portable Rest library. However, I had Fiddler running and I can see that the request actually succeeded (200) and there was no content returned.

Digging in to the source , it seems to me that the exception occurs in this method when it does a response.Content.ReadAsStringAsync() if Content is null -

In RestClient.cs -

private static async Task GetRawResponseContent([NotNull] HttpResponseMessage response)
{
//RWM: Explicitly check for NoContent... because the request was successful but there is nothing to do.
if (response.IsSuccessStatusCode && response.StatusCode != HttpStatusCode.NoContent)
{
return await response.Content.ReadAsStringAsync().ConfigureAwait(false);
}
return null;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions