ReadAsAsync <> in PCL Repack from System.Net.Http.Formatting library

I get the following error when trying to declare the ReadAsAsync <> extension method in retouching Bitrium.Http.Extensions System.Net.Http.Formatting.

The "SerializeToStreamAsync" method in the type 'System.Net.Http.ObjectContent' from the assembly 'Bitrium.Http.Extensions, Version = 1.0.0.0, Culture = neutral, PublicKeyToken = 43390f7aed073600' has no implementation.

I have something similar to the following code in a PCL project, which I am testing with a simple unit test. I do not implement a wait pattern, but I do not think this is related here.

public class RestApi()
{
    public void Get()
    {
        HttpResponseMessage response = new HttpResponseMessage();
        HttpClient client = new HttpClient();
        response = client.GetAsync("http://someUrl.com").Result;
        var modelList = response.Content.ReadAsAsync<List<Model>>().Result; // I get the exception here
     }
}

Method call:

var target = new RestApi();
target.Get();

-, ? Async, , , .

+4
1

Bitrium ReadAsAsync<T>, System.Net.Http.Formatting, Json.NET. , PCL lib, HttpClient (NuGet <package id="Microsoft.Net.Http" version="2.2.18" targetFramework="portable-net45+sl50+MonoAndroid10+MonoTouch10" />).

var resultString = response.Content.ReadAsStringAsync().Result;
Contacts = JsonConvert.DeserializeObject<List<T>>(resultString);

Json.NET.

+6

Source: https://habr.com/ru/post/1533773/


All Articles