NullReferenceException error inside EntityFramework code (EF error?), But my question is about the actions of the Entity Framework (v5) asynchronous controller and WebAPI.
Reproduction is difficult to recreate here, but essentially the code does the following:
public class AController : ApiController { private IUow _uow;
Inside Commit() , before DbContext.SaveChanges() , we will skip all DbChangeTracker.Entries() to set some common properties. But it's Entries() that errors before a single loop with a NullReferenceException deep inside System.Data.Entity.Infrastructure.DbChangeTracker.Entries()
Below is the call stack. This is all Framework code, and it feels like a bug, but actually my question is whether using the above async / awake between DbContext calls is allowed. In no case do we use multi-thread - async / await, because there are several I / O operations that we can perform using the async / await tool (a couple of Httpclient downloads + some asynchronous disk I / O).
System.NullReferenceException: Object reference not set to an instance of an object.\r\n at System.Data.Objects.DataClasses.RelatedEnd.IncludeEntity(IEntityWrapper wrappedEntity, Boolean addRelationshipAsUnchanged, Boolean doAttach)\r\n at System.Data.Objects.DataClasses.EntityReference`1.Include(Boolean addRelationshipAsUnchanged, Boolean doAttach)\r\n at System.Data.Objects.DataClasses.RelatedEnd.WalkObjectGraphToIncludeAllRelatedEntities(IEntityWrapper wrappedEntity, Boolean addRelationshipAsUnchanged, Boolean doAttach)\r\n at System.Data.Objects.DataClasses.RelatedEnd.IncludeEntity(IEntityWrapper wrappedEntity, Boolean addRelationshipAsUnchanged, Boolean doAttach)\r\n at System.Data.Objects.DataClasses.EntityCollection`1.Include(Boolean addRelationshipAsUnchanged, Boolean doAttach)\r\n at System.Data.Objects.DataClasses.RelatedEnd.WalkObjectGraphToIncludeAllRelatedEntities(IEntityWrapper wrappedEntity, Boolean addRelationshipAsUnchanged, Boolean doAttach)\r\n at System.Data.Objects.DataClasses.RelatedEnd.IncludeEntity(IEntityWrapper wrappedEntity, Boolean addRelationshipAsUnchanged, Boolean doAttach)\r\n at System.Data.Objects.DataClasses.EntityReference`1.Include(Boolean addRelationshipAsUnchanged, Boolean doAttach)\r\n at System.Data.Objects.DataClasses.RelatedEnd.WalkObjectGraphToIncludeAllRelatedEntities(IEntityWrapper wrappedEntity, Boolean addRelationshipAsUnchanged, Boolean doAttach)\r\n at System.Data.Objects.DataClasses.RelatedEnd.Add(IEntityWrapper wrappedTarget, Boolean applyConstraints, Boolean addRelationshipAsUnchanged, Boolean relationshipAlreadyExists, Boolean allowModifyingOtherEndOfRelationship, Boolean forceForeignKeyChanges)\r\n at System.Data.Objects.ObjectStateManager.PerformAdd(IEntityWrapper wrappedOwner, RelatedEnd relatedEnd, IEntityWrapper entityToAdd, Boolean isForeignKeyChange)\r\n at System.Data.Objects.ObjectStateManager.PerformAdd(IList`1 entries)\r\n at System.Data.Objects.ObjectStateManager.DetectChanges()\r\n at System.Data.Entity.Internal.InternalContext.GetStateEntries(Func`2 predicate)\r\n at System.Data.Entity.Infrastructure.DbChangeTracker.Entries()\r\n
c # nullreferenceexception entity-framework-5 entity-framework async-await
G. Stoynev Apr 09 '14 at 20:21 2014-04-09 20:21
source share