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

WebClient ResponseHeaders.HasKeys() returns incorrect result #27971

Closed
ighristov opened this issue Nov 20, 2018 · 7 comments
Closed

WebClient ResponseHeaders.HasKeys() returns incorrect result #27971

ighristov opened this issue Nov 20, 2018 · 7 comments

Comments

@ighristov
Copy link

WebClient's ResponseHeaders.HasKeys() returns false when there actually are keys and they are reported correctly through AllKeys property. The code below asserts correctly in .NET Framework 4.7.2 and fails in .NET Core 2.1:

using (var client = new WebClient())
{
    var data = client.DownloadData("https://img-prod-cms-rt-microsoft-com.akamaized.net/cms/api/am/imageFileData/RE1Mu3b?ver=5c31");
    System.Diagnostics.Debug.Assert(client.ResponseHeaders.HasKeys());
}
@ighristov ighristov changed the title WebClient ResponseHeaders.HasKeys() incorrectly returns false WebClient ResponseHeaders.HasKeys() returns incorrect result Nov 20, 2018
@Sebazzz
Copy link

Sebazzz commented Nov 21, 2018

This appears to be due to WebHeaderCollection actually using an internal NameValueCollection, but at the same time inheriting from NameValueCollection. The inner NameValueCollection contains the data and some members, like AllKeys are properly overwritten. HasKeys is not virtual and cannot be overwritten and returns the contents of the WebHeaderCollection itself, which is empty.

@GSPP
Copy link

GSPP commented Dec 1, 2018

This collection design is really messed up 😁

@caesar-chen
Copy link
Contributor

Per platform-compat repo:

WebClient is on life-support only (that is, only critical fixes, no new improvements, enhancements). Use HttpClient instead.

Does this issue only happen with WebClient.ResponseHeaders? Have you tried HttpClient?

@remcoros
Copy link
Contributor

remcoros commented Dec 5, 2018

NameValueCollection has "InternalHasKeys" which is virtual.

looking at referencesource (https://github.com/Microsoft/referencesource/blob/3b1eaf5203992df69de44c783a3eda37d3d4cd10/System/net/System/Net/WebHeaderCollection.cs#L1930), this seems to be missing from corefx

@karelz
Copy link
Member

karelz commented Oct 1, 2019

Triage: It needs closer look to decide what is the right decision. We may move the type maybe, but is that problematic? Is that the best solution?
Or maybe promote one internal constructor to public ...

Copy link
Contributor

Due to lack of recent activity, this issue has been marked as a candidate for backlog cleanup. It will be closed if no further activity occurs within 14 more days. Any new comment (by anyone, not necessarily the author) will undo this process.

This process is part of our issue cleanup automation.

@dotnet-policy-service dotnet-policy-service bot added backlog-cleanup-candidate An inactive issue that has been marked for automated closure. no-recent-activity labels Apr 1, 2024
Copy link
Contributor

This issue will now be closed since it had been marked no-recent-activity but received no further activity in the past 14 days. It is still possible to reopen or comment on the issue, but please note that the issue will be locked if it remains inactive for another 30 days.

@dotnet-policy-service dotnet-policy-service bot removed this from the Future milestone Apr 16, 2024
@karelz karelz added this to the 9.0.0 milestone May 14, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Jun 14, 2024
@dotnet-policy-service dotnet-policy-service bot removed no-recent-activity backlog-cleanup-candidate An inactive issue that has been marked for automated closure. labels Jun 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants