Как исправить System.ArgumentNullException: значение не может быть нулевым - PullRequest
0 голосов
/ 08 апреля 2019

Я создаю это приложение MVC, и у меня есть тот же код ниже для другого метода именования / формулировок.Тем не менее, этот метод всегда выдает эту ошибку:

System.ArgumentNullException: Value cannot be null.

Parameter name: source

Я искал везде, но мне не удалось решить эту проблему:

Код от моего контроллера:

    public List<Quote> GetQuote(string symbol1) //this action method returns the quote API endpoint 
    {
        // string to specify information to be retrieved from the API
        string IEXTrading_API_PATH = BASE_URL + "stock/" + symbol1 + "/quote";

        // initialize objects needed to gather data
        string CompanyQuote = "";
        List<Quote> DailyQuote = new List<Quote>();
        httpClient.BaseAddress = new Uri(IEXTrading_API_PATH);

        // connect to the API and obtain the response
        HttpResponseMessage response = httpClient.GetAsync(IEXTrading_API_PATH).GetAwaiter().GetResult();

        // now, obtain the Json objects in the response as a string
        if (response.IsSuccessStatusCode)
        {
            CompanyQuote = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
        }

        // parse the string into appropriate objects
        if (!CompanyQuote.Equals(""))
        {
            QuoteRoot quoteroot = JsonConvert.DeserializeObject<QuoteRoot>(CompanyQuote,
              new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
            DailyQuote = quoteroot.quote.ToList();
        }

        // fix the relations. By default the quotes do not have the company symbol
        //  this symbol serves as the foreign key in the database and connects the quote to the company
        foreach (Quote quotee in DailyQuote)
        {
            quotee.companysymbol = symbol1;
        }

        return DailyQuote;
    }

Строка, возвращающая эту ошибку, находится в этом блоке:

    // parse the string into appropriate objects
    if (!CompanyQuote.Equals(""))
    {
        QuoteRoot quoteroot = JsonConvert.DeserializeObject<QuoteRoot>(CompanyQuote,
          new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
        DailyQuote = quoteroot.quote.ToList();
    }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...