MongoFramework icon indicating copy to clipboard operation
MongoFramework copied to clipboard

NullReference in DetectChanges

Open grounzero opened this issue 4 years ago • 1 comments

I've been using this library for a couple of days and sometimes get a NullReference error when callling SaveChangesAsync.

at MongoFramework.Infrastructure.EntityEntryContainer.DetectChanges()

Looking into this method I see EntryLookupByType.Values has 2 values with the first being null which is throwing the exception.

How can I prevent this?

grounzero avatar Aug 17 '21 10:08 grounzero

That is very strange - not sure why there would be a null entry there. There should only be two code paths that add items and those items should only be added by the code here:

https://github.com/TurnerSoftware/MongoFramework/blob/bc0ce2ff7fd59eb279c7e344f89105bfeb72e89e/src/MongoFramework/Infrastructure/EntityEntryContainer.cs#L108-L119

Are you by chance sharing an instance of a MongoDbContext across threads?

Turnerj avatar Aug 17 '21 12:08 Turnerj