Is Microsoft.AspNet.WebApi.Client supported in .NET Core or not?

后端 未结 3 885
鱼传尺愫
鱼传尺愫 2021-02-13 12:59

I\'m currently trying to do some JSON formatting using the HttpClient in .NET Core and MediaTypeFormatters. Especially the function "ReadAsAsync(..., MediaTypeFormatter, ..

相关标签:
3条回答
  • 2021-02-13 13:48

    Update:

    Microsoft.AspNet.WebApi.Client version 5.2.4 was released on 2018-02-12.

    Thanks @whitney-kew @jaquez


    The package is not fully compatible with dotnetcore now. However there's workaround for this. You have to edit project.csproj like below:

    <Project Sdk="Microsoft.NET.Sdk">
      <PropertyGroup>
       <TargetFramework>netstandard1.4</TargetFramework>
       <PackageTargetFallback>portable-net451+win8</PackageTargetFallback>
      </PropertyGroup>
      <ItemGroup>
        <PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.3" />
        <PackageReference Include="System.Runtime.Serialization.Xml" Version="4.3.0-*" />
        <PackageReference Include="System.Xml.XmlSerializer" Version="4.3.0-*" />
      </ItemGroup> 
    </Project>
    

    Please refer to this github issue for details:

    https://github.com/aspnet/Home/issues/1558

    I think the new Microsoft.AspNet.WebApi.Client version (5.2.4) should fix this, but it's not released yet, maybe in late 2017.

    0 讨论(0)
  • 2021-02-13 13:49

    In addition to the other answers, there's also the System.Net.Http.Json package that uses the new Json serializer instead of Newtonsoft's.

    The usage is slightly different than using Microsoft.AspNet.WebApi.Client.

    httpClient.GetFromJsonAsync<Type>(uri);
    

    There's a number of other overloads as well.

    0 讨论(0)
  • 2021-02-13 13:53

    Microsoft.AspNet.WebApi.Client 5.2.4-preview1 is available now at https://www.nuget.org/packages/Microsoft.AspNet.WebApi.Client/5.2.4-preview1, as of the first week of January 2018. I was able to add it to my .NET Core library today, and it builds successfully.

    0 讨论(0)
提交回复
热议问题