Skip to content

Missing ObjectContent class in System.Net.Http #16538

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

Closed
chadly opened this issue Feb 27, 2016 · 10 comments
Closed

Missing ObjectContent class in System.Net.Http #16538

chadly opened this issue Feb 27, 2016 · 10 comments

Comments

@chadly
Copy link

chadly commented Feb 27, 2016

It appears ObjectContent didn't make it among the various subclasses of HttpContent (StreamContent, StringContent, etc.). Is this a bug or is there another way to use HttpClient to POST json somewhere?

e.g.

var value = new MyType();
client.PostAsync("http://example.com/", new ObjectContent<MyType>(value, new JsonMediaTypeFormatter()))
@davidsh
Copy link
Contributor

davidsh commented Feb 27, 2016

The set of *Content classes in HttpClient is the same as .NET Framework.

ASP.NET WebAPI did have a set of extension classes with JSON formatting.

cc: @danroth27

@chadly
Copy link
Author

chadly commented Feb 27, 2016

Ah, thanks I see now. After reading aspnet/Mvc#1639, I added a reference to Microsoft.Aspnet.WebApi.Client package and it now works even though that package doesn't explicitly target .net core.

Will that package be updated to target .net core?

@chadly chadly closed this as completed Feb 27, 2016
@davidsh
Copy link
Contributor

davidsh commented Feb 27, 2016

Will that package be updated to target .net core?

The ASP.NET team can answer that question better. Feel free to open an issue on the aspnet/mvc repo.

@davidsh davidsh removed their assignment Feb 27, 2016
@doublnt
Copy link

doublnt commented Feb 27, 2017

Can you tell me , what should I replace the

Content = new ObjectContent<ClubUserDto>(user, new JsonMediaTypeFormatter(), "application/json")

in .net core now?

@davidsh
Copy link
Contributor

davidsh commented Feb 27, 2017

The ASP.NET team owns the libraries that contain the ObjectContent class. It is not part of the .NET Framework and is not part of .NET Core itself.

Please follow up with @danroth27. I also suggest you ask this question in the ASP.NET repo:
https://github.com/aspnet/home

@danroth27
Copy link
Member

@Eilon @dougbu I believe the work is pretty much done. We are just waiting to align the release with the next update of ASP.NET Web API 2. You can grab the latest build of the package from http://myget.org/gallery/aspnetwebstacknightly.

@Eilon
Copy link
Contributor

Eilon commented Mar 1, 2017

Yup I think we're very close to getting this out. We have most of the legwork done, and in the meantime you can try out the nightly package feed to see that it resolves the issues you have with .NET Core support.

@pavlo-p
Copy link

pavlo-p commented Oct 5, 2017

Try to use JsonSerializer + StringContent

@chadly
Copy link
Author

chadly commented Oct 5, 2017

For anyone interested, you can add a reference to the .net standard compatible Microsoft.AspNet.WebApi.Client v5.2.4 which is not released yet because reasons.

See aspnet/Mvc#5822

@danroth27
Copy link
Member

We plan to release Microsoft.AspNet.WebApi.Client 5.2.4 in the next month or so pending final verification.

@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
@ghost ghost locked as resolved and limited conversation to collaborators Jan 2, 2021
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