HttpContentExtensions.ReadAsAsync错误

dot*_*e82 6 .net c# asp.net-web-api

在对同一个类中的泛型方法进行方法调用时,我收到以下异常:

System.MissingMethodException:找不到方法:'System.Threading.Tasks.Task`1 System.Net.Http.HttpContentExtensions.ReadAsAsync(System.Net.Http.HttpContent)'

方法调用如下:

CarMdRootMessage<List<v20.CarMdDiagnosticReport>> report = this.CarMdGet<List<v20.CarMdDiagnosticReport>>(string.Format("report/diagnostic?uploadID={0}", string.Join(",", uploadIds)));
Run Code Online (Sandbox Code Playgroud)

看起来像"Microsoft.AspNet.WebApi.Client"NuGet包在项目之间不同步的问题,但是现在我已经将它们全部放在5.2.3上并且仍然存在问题.

我还认为这可能是一个.NET 4.5问题所以我已经将所有项目升级到.NET 4.5.2,但我仍然遇到错误.

谁看过这个吗?

Gui*_*ino 5

您可能需要在 app.config 中添加绑定重定向

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
  <dependentAssembly>
    <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.2.0.0" />
  </dependentAssembly>
</assemblyBinding>
Run Code Online (Sandbox Code Playgroud)


igo*_*024 3

我遇到了同样的问题,并设法通过删除已安装的System.Net.Http NuGet 包 安装 Microsoft.Net.Http NuGet 包(均由 Microsoft 提供)来解决该问题。