为了账号安全,请及时绑定邮箱和手机立即绑定

值不能为空。参数名称:第一个

值不能为空。参数名称:第一个

C#
RISEBY 2021-05-06 18:16:35
当我运行下面的代码时,出现以下错误:值不能为空。参数名称:第一个这是我的代码:private async void CallWebApiDetails(){    WebApiService oWS = new WebApiService();    lstLocalDBAlertsID = new List<string>();    try    {        ErrorHandle err = await oWS.GetAllAlerts();        var lstdistinct = err.lstServerAlertsIDs.Except(lstLocalDBAlertsID).ToList();        if (lstdistinct != null)        {            var lstOrderedLst = lstdistinct.OrderBy(i => i).ToList();            if (lstOrderedLst.Count > 0)            {                for (int i = 0; i < lstOrderedLst.Count; i++)                {                    AlertData oAlertData = new AlertData();                    oAlertData.Where.AlertId.Value = lstOrderedLst[i];                    if (!oAlertData.Query.Load())                    {                        ErrorHandle oErr = new ErrorHandle();                        oErr = await oWS.getSpecificAlert(lstOrderedLst[i]);                        await SaveAlertData(Convert.ToInt32(lstOrderedLst[i]), oErr);                    }                }            }        }    }    catch (Exception ex)    {        LogError oLE = new LogError();        oLE.logEx(ex, "CallWebApiDetails");    }}有人可以告诉我我的代码有什么问题吗?
查看完整描述

1 回答

?
慕标琳琳

TA贡献1830条经验 获得超9个赞

该Except扩展方法具有first作为this参数; 它被定义为


public static IEnumerable<TSource> Except<TSource>(

    this IEnumerable<TSource> first, IEnumerable<TSource> second)

{

    if (first == null)

    {

        throw Error.ArgumentNull("first");

    }

    // ...

}

所以大概在这一行:


var lstdistinct = err.lstServerAlertsIDs.Except(lstLocalDBAlertsID).ToList()

的值err.lstServerAlertsIDs就是null。所以:解决这个问题。


注意:最好将调试器与断点一起使用,或者至少要使用堆栈跟踪来确定哪条线失败,这是一个好主意。您不能总是(或什至经常)推断这样的上下文。


查看完整回答
反对 回复 2021-05-29
  • 1 回答
  • 0 关注
  • 193 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信