I have a system which manages tasks, and after leaving it running overnight came back to a NullReferenceException; "Object reference not set to an isntance of an object."
I've read half a hundred other NullReferenceException SO posts, and none seem to share my issue. The system ran perfectly fine for 8 hours before crashing, while debugging I can see the locals of the line the exception was raised, and nothing is null. Here is some code
if (ackList.Count > 0)
{
for (int i = 0; i < ackList.Count; i++)
{
if ((t.taskID == ackList[i].taskID) && (ackList[i].associatedFile != null)) //exception raised on this line
{
//process task as complete
//Locals as below:
//t.taskID = 68941
//i = 30840
//ackList.Count = 30841
//ackList[i].taskID = 68941
//ackList[i].associatedFile = {TaskACKAssociatedFile[1]}
}
}
}
I inherited this code from a previous dev, and the loop was then a foreach which fell apart when ackList increased during the running of the loop; ackList stores all acknowledgement messages and is populated in a different thread.
The exception is raised off the if statement, where at least in this case there are no null values.
EDIT: I would argue that this is not an exact duplicate of What is a NullReferenceException, and how do I fix it? . All my objects are initiated, and none of the locals used are null. That question is asking what a NRE is, of which I am frightfully aware, and none of the answers, even that incredibly thorough top answer, helps me whatsoever.