'Entity Framework ErrorHandlingValueReader

I've got an error that I cannot seem to track down when my page is trying to load a list of files from the server.

I pulled this code out of a TFS shelf-set, and it was running when it was saved.

I have tried breaking down the line where the error occurs (commented out in the code shown) and added extra checks just in case the data happen to have null entries.

Here is a snippet of it:

if (roadmap != null)
{
    List<Guid> taskList = lstRoadmapTaskMapping.Select(o => o.TaskGuid).ToList();
    var list = SessionManager.CurrentContext.TaskDecisionDetails.Where(x => x.Task != null && x.Task.TaskGuid != null && taskList.Contains(x.Task.TaskGuid));
    var lstTaskDecisionDetail = new List<TaskDecisionDetail>(list);
    //List<TaskDecisionDetail> lstTaskDecisionDetail = SessionManager.CurrentContext.TaskDecisionDetails.Where(o => taskList.Contains(o.Task.TaskGuid)).ToList();

    lstOfTasks = lstTaskDecisionDetail.Select(o => o.TaskToStart).ToList();
    lstOfTasks.AddRange(lstTaskDecisionDetail.Select(o => o.AssociatedTaskGuid ?? Guid.Empty).ToList());

    lstOfTasks.AddRange(SessionManager.Current.CurrentContext.TaskDecisionDetailRoutes.Where(o => taskList.Contains(o.TaskDecisionDetail.Task.TaskGuid)).Select(o => o.NATaskGuid).ToList());
    List<Guid> roadmapMappingGuid = lstRoadmapTaskMapping.Where(o => lstOfTasks.Contains(o.TaskGuid)).Select(o => o.RoadmapTaskMappingGuid).ToList();

    treeHL.JSProperties["cp_NoDeleteIDs"] = string.Join(",", roadmapMappingGuid);
}

The exception is thrown at the green highlighted line in the screenshot below:

code screen

The error message is this common one:

Object reference not set to an instance of an object.

The question below goes fully into that error message.

What does "Object reference not set to an instance of an object" mean?

That is what got me to break the single line (commented out at the moment) into 2 lines, hoping that would solve my error.

The StackTrace is pointing to the Entity framework:

at System.Data.Entity.Core.Common.Internal.Materialization.Shaper.ErrorHandlingValueReader`1.GetValue(DbDataReader reader, Int32 ordinal)

error screen

What else could be null in the expression?

How can I go about debugging this error?

I am also curious about what it means whenever the debugger stops on a green breakpoint instead of a yellow breakpoint.



Solution 1:[1]

It turned out that the database had corrupt entries.

Loading the data to an Entity was causing validation errors with its constraints.

I restored the database from a recent version and the issues went away.

I started to just delete this question, but it might help someone down the road.

Solution 2:[2]

Had the same issue with Entity Framework for .NET Framework.

Had a class Customer with a nested Dealer class, something like:

class Customer {
int Id;
Dealer Dealer;
}

class Dealer {
int Id;
bool IsActive;
}

The isActive flag on the Database was implemented as 'bit' (1 or 0), but the constraint on that column was that it can also be NULL. During migration the isActive flag was left out from INSERTS so it took on the default value of NULL for some Dealer records.

When running _customerRepository.GetAll() EntityFramework could not map the null to boolean within the Dealer object and apparently the Dealer object was not created, which caused the issue.

Hope that helps anyone.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 jp2code
Solution 2 Srutu-tutu