Core: ReadAsAsync<T> Alternatives

Created on 9 Jan 2019  路  3Comments  路  Source: dotnet/core

ReadAsAsync method is not compatible with .NET Core2.2

General

Hey, I'm working on an API. I want to map HttpResponseMessage object's Content field into a domain model. I know I can do by ReadAsStringAsync then deserialize it but I don't really want, that much work for simple mapping. I've couldn't found yet but are there any alternatives for that?
I can't suppress the warning since it's a blocker on deployment side.

Summary of process:

c# var taskResult= await _httpRequestService.GetAsync(); var searchResult = await taskResult.Content.ReadAsAsync<MyModel>();

Warning(Error in this case):

Package 'System.Net.Http.Formatting.Extension 5.2.3' was restored using .NETFramework,Version=v4.6.1' instead of the project target framework '.NETCoreApp,Version=v2.2'.

Most helpful comment

Super catch!
I thought it was a built-in class and didn't verify.
Thanks. @karelz @svick

All 3 comments

The package System.Net.Http.Formatting.Extension that you seem to be using is not from Microsoft. I believe you should use the Microsoft.AspNet.WebApi.Client package instead, which should support .Net Core 2.x.

Looks like problem with external 3rd party NuGet package, closing. Thanks @svick for your analysis.
If you find a repro without it, please let us know and we can reopen.

Super catch!
I thought it was a built-in class and didn't verify.
Thanks. @karelz @svick

Was this page helpful?
0 / 5 - 0 ratings