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.Net.Http.WebRequest works as a Microsoft.NETCore.App but not as a NETStandard.Library #17034

Closed
jeffschwMSFT opened this issue Apr 19, 2016 · 5 comments
Assignees
Labels
area-System.Net packaging Related to packaging question Answer questions and provide assistance, not an issue with source code or documentation.
Milestone

Comments

@jeffschwMSFT
Copy link
Member

The following code snippet and project.json combo restore, build and run:

program.cs
...
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

project.json
{
"version": "1.0.0-*",
"compilationOptions": {
"emitEntryPoint": true
},
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0-rc2-3002394"
}
},
"frameworks": {
"netcoreapp1.0": {}
}
}

Using the same code and creating a library does not
http.tar.gz
build (note the original library code did not have an entry point, but this was just for simplicity).

project.json
{
"version": "1.0.0-*",
"compilationOptions": {
"emitEntryPoint": true
},
"dependencies": {
"NETStandard.Library" : "1.5.0-rc2-23931"
},
"frameworks": {
"netstandard1.5": {}
}
}

/Users/xyz/Documents/Projects/bug/http/Program.cs(17,9): error CS0246: The type or namespace name 'HttpWebRequest' could not be found (are you missing a using directive or an assembly reference?)
/Users/xyz/Documents/Projects/bug/http/Program.cs(17,50): error CS0103: The name 'WebRequest' does not exist in the current context
/Users/xyz/Documents/Projects/bug/http/Program.cs(17,35): error CS0246: The type or namespace name 'HttpWebRequest' could not be found (are you missing a using directive or an assembly reference?)
/Users/xyz/Documents/Projects/bug/http/Program.cs(21,20): error CS0246: The type or namespace name 'HttpWebResponse' could not be found (are you missing a using directive or an assembly reference?)
/Users/xyz/Documents/Projects/bug/http/Program.cs(21,48): error CS0246: The type or namespace name 'HttpWebResponse' could not be found (are you missing a using directive or an assembly reference?)

dotnet --info
.NET Command Line Tools (1.0.0-rc2-002394)

Product Information:
Version: 1.0.0-rc2-002394
Commit Sha: 3a423b1080

Runtime Environment:
OS Name: Mac OS X
OS Version: 10.11
OS Platform: Darwin
RID: osx.10.11-x64

@davidsh
Copy link
Contributor

davidsh commented Apr 19, 2016

System.Net.HttpWebRequest is part of the System.Net.Requests contract.

The System.Net.Requests contract is NOT part of the NETStandard.Library meta-package. If you want to use this API, you will need to add an explicit reference to System.Net.Requests contract library.

We recommend you move to the newer System.Net.Http API surface which includes HttpClient. This contract/library is part of NETStandard.Library.

In general, for better app performance and features, we recommend developers move away from HttpWebRequest and adopt HttpClient API surface.

@jeffschwMSFT
Copy link
Member Author

Thanks @davidsh , from a discoverability standpoint how are people recommended to diagnosis this issue?

@davidsh
Copy link
Contributor

davidsh commented Apr 19, 2016

@ericstj or @weshaggard or @stephentoub would be better able to answer those kind of general CoreFx questions.

@weshaggard
Copy link
Member

This isn't any different then someone trying to use any API outside of NETStandard.Library, which isn't great you just have to know what references to add. I believe we are working on adding some VS support for finding packages for some APIs and updating references, @Petermarcu might know more.

@ericstj
Copy link
Member

ericstj commented Apr 21, 2016

We have different meta packages with different content. Nowhere do we doc that they should be the same nor does common convention imply that two packages with different names should have the same content.
I think the general problem is being tracked by https://github.com/dotnet/corefx/issues/4343.

@ericstj ericstj closed this as completed Apr 21, 2016
@msftgits msftgits transferred this issue from dotnet/corefx Jan 31, 2020
@msftgits msftgits added this to the 1.0.0-rtm milestone Jan 31, 2020
@dotnet dotnet locked as resolved and limited conversation to collaborators Jan 1, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Net packaging Related to packaging question Answer questions and provide assistance, not an issue with source code or documentation.
Projects
None yet
Development

No branches or pull requests

5 participants