[英]Value cannot be null. Parameter name: 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");
}
}
有人可以告訴我我的代碼有什么問題嗎?
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
。 所以:解決這個問題。
注意:最好將調試器與斷點一起使用,或者至少要使用堆棧跟蹤來確定哪一行失敗。 您不能總是(甚至經常)推斷這樣的上下文。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.