Pergunta

I am getting the following error when trying to envoke the ReadAsAsync<> extension method in the Bitrium.Http.Extensions repack of System.Net.Http.Formatting.

Method 'SerializeToStreamAsync' in type 'System.Net.Http.ObjectContent' from assembly 'Bitrium.Http.Extensions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=43390f7aed073600' does not have an implementation.

I have something similar to the following code in a PCL project which I am testing via a simple unit test. I am not implementing the await pattern, but I do not believe it 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
     }
}

The call to the method:

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

Is there anything I can do about it at this point? I do not need the Async feature necessarily, so another implementation that still converted my response to my model would be fine as well.

Foi útil?

Solução

Instead of using Bitrium repackage in attempt to reuse the ReadAsAsync<T> extension method that is in System.Net.Http.Formatting, I opted for Json.NET instead. Therefore did not need to rely on the repackage, but rather just on the current standard implementations of the PCL build of the lib containing 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);

I found this post helful for the new Json.NET piece.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top