下面我粘贴了一些代码。在正文的第一行上,我调用了一个等待呼叫Task<IEnumerable<SkuGcn>> GetSkuGcnList();在最后一行中,在mapPromise.GetAwaiter()中,当获得此异常的结果时,它将引发:


System.Private.CoreLib.ni.dll中发生了类型为'System.IO.FileNotFoundException'的异常,但未在用户代码中处理

附加信息:无法加载文件或程序集'System.Runtime.Serialization.Xml,版本= 4.0.0.0,区域性=中性,PublicKeyToken = b03f5f7f11d50a3a'。该系统找不到指定的文件。


我知道正在调用GetSkuGcnList()调用的服务,因为我可以设置一个断点,并且在进行调用时会在该点处中断。然后服务似乎返回了。

这段代码在ASP.NET 5 RC1上可以正常工作,但是现在在ASP.Net Core 1.0发行版中效果不佳。

任何帮助将不胜感激!

        public ProductItemsCacheStore(IItemsProductCacheRepository itemsRepo, IProductAvailabilityPricing proxyGoliathApi,
        IProductItemListRepo itemsListsRepo, IItemPricesCacheRepo itemPricesRepo)
        {
            var mapPromise = proxyGoliathApi.GetSkuGcnList();
            _items = itemsRepo.GetAllProductOrderListForCache();
            _itemsLists = itemsListsRepo.GetItemListsForCache();
            _priceZones = itemPricesRepo.GetAllPriceZonesAndItemPrices();
            MergeProductsWithGcn(_items, mapPromise.GetAwaiter().GetResult());
        }


我的project.json看起来像这样:

{
  "version": "1.0.0-alpha.1",
  "description": "AvailabilityPricingClient Class Library",
  "authors": [ "irving.lennert" ],
  "packOptions": {
    "tags": [ "" ],
    "projectUrl": "",
    "licenseUrl": ""
  },

  "tooling": {
    "defaultNamespace": "AvailabilityPricingClient"
  },

  "dependencies": {
    "Microsoft.NETCore.App": {
      "version": "1.0.0",
      "type": "platform"
    },
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
    "Microsoft.Extensions.Configuration.Json": "1.0.0",
    "Microsoft.Extensions.Logging": "1.0.0",
    "Microsoft.Extensions.Logging.Console": "1.0.0",
    "Microsoft.Extensions.Logging.Debug": "1.0.0",
    "Microsoft.AspNet.WebApi.Client": "5.2.3"
  },

  "frameworks": {
    "netcoreapp1.0": {
      "imports": [
        "dotnet5.6",
        "portable-net45+win8"
      ]
    }
  }
}


GetSkuGcnList()的实现是这样的:

    public async Task<IEnumerable<SkuGcn>> GetSkuGcnList()
    {
        HttpResponseMessage response = _client.GetAsync("/api/skuGcnList").Result;

        if (response.IsSuccessStatusCode)
        {
            var skuGcns = await response.Content.ReadAsAsync<IEnumerable<SkuGcn>>();
            return skuGcns;
        }

        return null;
    }

最佳答案

我已经确定我正在调用的程序集对于ASP.Net Core版本无法正常工作。如果您在上面的project.json中查找,则此行:

"Microsoft.AspNet.WebApi.Client": "5.2.3"


我已将该行更改为以下行:

"System.Net.Http": "4.1.0"


该程序集没有公开相同的API,因此我不得不将实现代码更改为:

    public async Task<IEnumerable<SkuGcn>> GetSkuGcnList()
    {
        HttpResponseMessage response = _client.GetAsync("/api/skuGcnList").Result;

        if (response.IsSuccessStatusCode)
        {
            var skuGcns = await response.Content.ReadAsStringAsync()
                .ContinueWith<IEnumerable<SkuGcn>>(getTask =>
                {
                    return JsonConvert.DeserializeObject<IEnumerable<SkuGcn>>(getTask.Result);
                });
            return skuGcns;
        }

        return null;
    }


该解决方案运行良好。重要的是要注意,我在发布时也遇到了同样的问题,而且它们也有些复杂,因此我将提供另一个我要打的电话,以供有兴趣的人发布。

    public async Task<IEnumerable<Availablity>> GetAvailabilityBySkuList(IEnumerable<string> skuList)
    {
        var output = JsonConvert.SerializeObject(skuList);
        HttpContent contentPost = new StringContent(output, System.Text.Encoding.UTF8, "application/json");
        HttpResponseMessage response = _client.PostAsync("/api/availabilityBySkuList", contentPost).Result;

        if (response.IsSuccessStatusCode)
        {
            var avail = await response.Content.ReadAsStringAsync()
                .ContinueWith<IEnumerable<Availablity>>(postTask =>
                {
                    return JsonConvert.DeserializeObject<IEnumerable<Availablity>>(postTask.Result);
                });
            return avail;
        }

        return null;
    }


感谢所有的贡献!

09-25 18:30