Skip to content

HttpResponseMessage.Content nullable annotation is... annoying #35859

@stephentoub

Description

@stephentoub

The annotation we have is correct: it can be null. However, it'll never be null from the built-in handlers, yet developers are forced to either then do unnecessary null checks or !-away the nullable warnings, e.g.

using (var resp = await client.GetAsync(...))
{
    string s = await resp.Content.ReadAsStringAsync(); // nullable warning; need to do `Content!` instead
}

I wonder if we should change HttpResponseMessage.Content to be non-null returning and to lazily-initialize an empty content object if it would otherwise be null.

cc: @scalablecory, @davidsh, @safern, @buyaa-n

Metadata

Metadata

Assignees

Labels

area-System.Net.HttpenhancementProduct code improvement that does NOT require public API changes/additions

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions