【问题标题】:Method not found GetJsonAsync while using Flurl使用 Flurl 时找不到 GetJsonAsync 方法
【发布时间】:2019-07-04 09:38:41
【问题描述】:

我正在尝试使用 Flurl 调用 api,这是我的请求,它只在我的测试服务器上失败,但也适用于实时服务器和本地主机

PickUp responseAsPickUpPointServiceResponse = null;
        try
        {
            responseAsPickUpPointServiceResponse =
                await new Flurl.Url(_baseUrl + "/rest//v1/servicepoint/findByPostalCode.json")
                    .SetQueryParam("apikey", APIKEY_WEB1)
                    .SetQueryParam("countryCode", countrycode)
                    .SetQueryParam("postalCode", zipcode)
                    .WithHeader("Accept", "application/json;charset=UTF-8")
                    .GetJsonAsync<PickUp>();
        }

但它失败并出现错误

找不到方法:'System.Threading.Tasks.Task`1 Flurl.Http.GeneratedExtensions.GetJsonAsync(Flurl.Http.IFlurlRequest, System.Threading.CancellationToken, System.Net.Http.HttpCompletionOption)强>

有人知道如何解决这个问题吗?

【问题讨论】:

  • 你知道如何解决这个问题吗?
  • @jorgeACacon 很遗憾没有
  • 每次构建应用程序后我都必须执行 iisreset...

标签: c# flurl


【解决方案1】:

同样,我在运行我的集成测试时遇到了同样的错误Method not found [...] GetJsonAsync,尽管它在单元测试中运行良好。

就我而言,有两个项目的Flurl.Http 版本不匹配:

main.csproj

<Project Sdk="Microsoft.NET.Sdk">
   <ItemGroup>
     <PackageReference Include="Flurl" Version="3.0.0" />
     <PackageReference Include="Flurl.Http" Version="3.0.0" />
   </ItemGroup>
   <ItemGroup>
     <ProjectReference Include="..\other\imported.csproj" />
   </ItemGroup>
</Project>

imported.csproj

<Project Sdk="Microsoft.NET.Sdk">
   <ItemGroup>
     <PackageReference Include="Flurl" Version="2.8.2" />
     <PackageReference Include="Flurl.Http" Version="2.4.2" />
   </ItemGroup>
</Project>

该错误已通过将 Flurl 版本更改为 3.0.1 修复:

在两个文件中:

<PackageReference Include="Flurl" Version="3.0.1" />
<PackageReference Include="Flurl.Http" Version="3.0.1" />

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-02-10
    • 1970-01-01
    • 1970-01-01
    • 2016-05-21
    • 2015-11-24
    • 2020-01-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多