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

Removed nullability checks from FormUrlEncodedContent ctor #55410

Merged

Conversation

ManickaP
Copy link
Member

@ManickaP ManickaP commented Jul 9, 2021

As @stephentoub suggested, we can just avoid the problem by temporarily disabling nullability checks for the offending ctor.
Works with all following options:

new FormUrlEncodedContent(new Dictionary<string, string>());
new FormUrlEncodedContent(new Dictionary<string, string?>());
new FormUrlEncodedContent(new List<KeyValuePair<string?, string?>>());
new FormUrlEncodedContent(new List<KeyValuePair<string, string?>>());
new FormUrlEncodedContent(new List<KeyValuePair<string, string>>());

But still disallows passing in null itself:

new FormUrlEncodedContent(null); // warning CS8625: Cannot convert null literal to non-nullable reference type.

Fixes #38494
Closes #44458

@dotnet-issue-labeler
Copy link

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

@ghost
Copy link

ghost commented Jul 9, 2021

Tagging subscribers to this area: @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

Issue Details

As @stephentoub suggested, we can just avoid the problem by temporarily disabling nullability checks for the offending ctor.
Works with all following options:

new FormUrlEncodedContent(new Dictionary<string, string>());
new FormUrlEncodedContent(new Dictionary<string, string?>());
new FormUrlEncodedContent(new List<KeyValuePair<string?, string?>>());
new FormUrlEncodedContent(new List<KeyValuePair<string, string?>>());
new FormUrlEncodedContent(new List<KeyValuePair<string, string>>());

But still disallows passing in null itself:

new FormUrlEncodedContent(null); // warning CS8625: Cannot convert null literal to non-nullable reference type.

Fixes #38494
Closes #44458

Author: ManickaP
Assignees: -
Labels:

area-System.Net.Http, new-api-needs-documentation

Milestone: -

@ManickaP ManickaP requested a review from a team July 9, 2021 16:47
@ManickaP ManickaP force-pushed the mapichov/38494_formurlencodedcontent branch from 7693173 to ade9dc0 Compare July 9, 2021 17:06
@ManickaP ManickaP force-pushed the mapichov/38494_formurlencodedcontent branch from ade9dc0 to 8321bc5 Compare July 9, 2021 17:06
Copy link
Member

@MihaZupan MihaZupan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very cool trick

@ManickaP ManickaP merged commit ac53e65 into dotnet:main Jul 9, 2021
@ManickaP ManickaP deleted the mapichov/38494_formurlencodedcontent branch July 9, 2021 20:33
@karelz karelz added this to the 6.0.0 milestone Jul 15, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Aug 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
4 participants