我有一个 WebAPI
它具有以下代码段,其中在使用我的记录器记录的 try 块中编写的代码中存在 Null 引用异常。
但是在TargetSite
的Exception
登录,我收到 无效 MoveNext() 而不是编写此代码的方法名称。
什么可能是相同的原因?
public async Task<ResponseStatus> ProcessRCSCNotification(IList<RecurringSubscriptionModelV2> recurringSubscriptionList, string appCD)
{
foreach (var model in modelList)
{
// Some code
try
{
// Exception occurs here
}
catch (Exception ex)
{
// Logger is logging exception here
}
}
return null;
}
最佳答案
您有一个 async
方法有几个await
s。编译器将整个方法转换为 state machine而你的方法实际上只调用了这个状态机。
这个状态机类有提到 MoveNext()
现在包含您真正想做的所有工作的方法。
分析您的 NullReferenceException
你应该检查 StackTrace
异常的属性比TargetSite
.
关于c# - 在 Null 引用异常中使 MoveNext() 无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50815767/