Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullReference in DetectChanges #249

Open
grounzero opened this issue Aug 17, 2021 · 1 comment
Open

NullReference in DetectChanges #249

grounzero opened this issue Aug 17, 2021 · 1 comment
Labels

Comments

@grounzero
Copy link

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?

@Turnerj
Copy link
Member

Turnerj commented Aug 17, 2021

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:

else if (state != EntityEntryState.Detached)
{
RemoveEntry<TCollectionBase>(entry);
entry = new EntityEntry(entity, typeof(TCollectionBase), state);
AddEntry<TCollectionBase>(entry);
}
}
else if (state != EntityEntryState.Detached)
{
entry = new EntityEntry(entity, typeof(TCollectionBase), state);
AddEntry<TCollectionBase>(entry);
}

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants