When I run the code below, I get the following error:
Value cannot be null. Parameter name: first
Here is my code:
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");
}
}
Can somebody tell me what's wrong with my code?
The Except
extension method has first
as the this
parameter; it is defined as
public static IEnumerable<TSource> Except<TSource>(
this IEnumerable<TSource> first, IEnumerable<TSource> second)
{
if (first == null)
{
throw Error.ArgumentNull("first");
}
// ...
}
so presumably in this line:
var lstdistinct = err.lstServerAlertsIDs.Except(lstLocalDBAlertsID).ToList()
the value of err.lstServerAlertsIDs
is null
. So: fix that.
Note: it is a good idea to get familiar with using the debugger with breakpoints or at least the stack trace to identify which line is failing. You can't always (or even often) infer the context like this.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.