C# 值不能为null。参数名称:first

C# 值不能为null。参数名称:first,c#,asp.net,C#,Asp.net,运行下面的代码时,出现以下错误: 值不能为null。参数名称:first 这是我的密码: private async void CallWebApiDetails() { WebApiService oWS = new WebApiService(); lstLocalDBAlertsID = new List<string>(); try { ErrorHandle err = await oWS.GetAllAlerts();

运行下面的代码时,出现以下错误:

值不能为null。参数名称:first

这是我的密码:

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");
    }
}
private async void CallWebApiDetails()
{
WebApiService oWS=新的WebApiService();
lstLocalDBAlertsID=新列表();
尝试
{
ErrorHandle err=wait oWS.GetAllAlerts();
var lstdinctinct=err.lstServerAlertsIDs.Except(lstLocalDBAlertsID.ToList();
如果(lstdinctinct!=null)
{
var lstoredlst=lstdinctinct.OrderBy(i=>i.ToList();
如果(lstoredlst.Count>0)
{
for(int i=0;i

谁能告诉我我的代码有什么问题吗?

除了
扩展方法将首先作为
这个
参数;它被定义为

public static IEnumerable<TSource> Except<TSource>(
    this IEnumerable<TSource> first, IEnumerable<TSource> second)
{
    if (first == null)
    {
        throw Error.ArgumentNull("first");
    }
    // ...
}
err.lstServerAlertsIDs
的值为
null
。所以:解决这个问题


注意:最好熟悉使用带断点的调试器,或者至少使用堆栈跟踪来识别哪一行失败。你不能总是(甚至经常)像这样推断上下文。

Except扩展方法将
first
作为
这个
参数;它被定义为

public static IEnumerable<TSource> Except<TSource>(
    this IEnumerable<TSource> first, IEnumerable<TSource> second)
{
    if (first == null)
    {
        throw Error.ArgumentNull("first");
    }
    // ...
}
err.lstServerAlertsIDs
的值为
null
。所以:解决这个问题


注意:最好熟悉使用带断点的调试器,或者至少使用堆栈跟踪来识别哪一行失败。您不能总是(甚至经常)这样推断上下文。

错误发生在哪一行?错误发生在哪一行?