类型' System.AggregateException'的例外情况发生在WebApplication1.dll中但未在用户代码中处理

时间:2017-09-25 20:37:25

标签: c# exception controller

每当我尝试运行我的网络应用时,我会不时收到此异常: 类型" System.AggregateException'的例外情况发生在WebApplication1.dll中但未在用户代码"

中处理

异常由以下代码中的catch子句触发:

      public static IEnumerable<Airport> GetAirports(string url)
    {
        IEnumerable<Airport> airports = null;
        HttpResponseMessage response;
        // write some code that retrieves the content from the url, and 
        // convert it to a list of airports.
        using (var client = new HttpClient())
        {
            try
            {
                response = client.GetAsync(url).Result;
            }
            catch (Exception e)
            {

                throw e;
            }
      if (response.IsSuccessStatusCode)
      {
      // by calling .Result you are performing a synchronous call
      var responseContent = response.Content;

      // by calling .Result you are synchronously reading the result

      string responseString = responseContent.ReadAsStringAsync().Result;
      airports = JsonConvert.DeserializeObject<List<Airport>>
                 (responseString);

            }
        }
        return airports;
    }

0 个答案:

没有答案