无法对类型为 var 的空引用异常执行运行时绑定

Cannot perform runtime binding on a null reference Exception with var type

我正在尝试使用此 API 从 CRM 获取数据。我收到一个错误

Runtime binding on a null reference

每当我尝试从 data.fullname 获取值时。有什么办法可以解决吗?

谢谢

var response = httpClient.GetAsync("contacts?$select=fullname,emailaddress1").Result;
           
if (response.IsSuccessStatusCode)
{
    var accounts = response.Content.ReadAsStringAsync().Result;

    var jRetrieveResponse = JObject.Parse(accounts);

    dynamic collContacts = JsonConvert.DeserializeObject(jRetrieveResponse.ToString());

    try
    {
        foreach (var data in collContacts.value)
        {
            // You can change as per your need here
            if (data.fullname.Value != null)
            {
                success[i] = data.fullname.Value;
            }

            i ++;
        } 
    }
    catch (Exception)
    { 
         throw; 
    }
}
    

替换

if (data.fullname.Value != null)

有了这个

if  (!String.IsNullOrWhiteSpace(data.fullname.Value))

或替换

try
{
    foreach (var data in collContacts.value)
    {
        // You can change as per your need here
        if (data.fullname.Value != null)
        {
            success[i] = data.fullname.Value;
        }

        i ++;
    } 
}
catch (Exception)
{ 
     throw; 
}

try
{
    foreach (var data in collContacts.value)
    {
        success[i] = data?.fullname?.Value;
        i ++;
    } 
}
catch (Exception)
{ 
     throw; 
}