EntityDefinition.CollectionName becoming "randomly" null.
See original GitHub issueI’m scratching my head to understand why EntityDefinition.CollectionName is becoming “randomly” null. I say randomly, because it seems like 1 in 3 runs the issue crops up.
Happens when doing a basic query on a collection:
public IList<Contact> GetAll(Guid organizationId)
{
var contacts = _context.Contacts
.Where(b => b.OrganizationId == organizationId)
.ToList();
return contacts;
}
System.ArgumentNullException: Value cannot be null. (Parameter ‘name’)
at MongoDB.Driver.Core.Misc.Ensure.IsNotNullOrEmpty(String value, String paramName)
at MongoDB.Driver.MongoDatabaseImpl.GetCollection[TDocument](String name, MongoCollectionSettings settings)
at MongoFramework.Infrastructure.Linq.MongoFrameworkQueryProvider1.GetCollection() in C:\Users\dthk\Source\Repos\MongoFramework\src\MongoFramework\Infrastructure\Linq\MongoFrameworkQueryProvider.cs:line 87 at MongoFramework.Infrastructure.Linq.MongoFrameworkQueryProvider
1.GetBaseExpression() in C:\Users\dthk\Source\Repos\MongoFramework\src\MongoFramework\Infrastructure\Linq\MongoFrameworkQueryProvider.cs:line 38
at MongoFramework.Infrastructure.Linq.MongoFrameworkQueryable1..ctor(IMongoFrameworkQueryProvider provider) in C:\Users\dthk\Source\Repos\MongoFramework\src\MongoFramework\Infrastructure\Linq\MongoFrameworkQueryable.cs:line 23 at MongoFramework.Infrastructure.EntityReader
1.AsQueryable() in C:\Users\dthk\Source\Repos\MongoFramework\src\MongoFramework\Infrastructure\EntityReader.cs:line 23
at MongoFramework.MongoDbSet1.GetQueryable() in C:\Users\dthk\Source\Repos\MongoFramework\src\MongoFramework\MongoDbSet.cs:line 191 at MongoFramework.MongoDbSet
1.get_Provider() in C:\Users\dthk\Source\Repos\MongoFramework\src\MongoFramework\MongoDbSet.cs:line 201
at System.Linq.Queryable.Where[TSource](IQueryable1 source, Expression
1 predicate)
at RuleEngine.Infrastructure.Repositories.ContactRepository.GetAll(Guid organizationId) in C:\Users\dthk\Source\Repos\AdvocacySolutions\RuleEngine.Infrastructure\Repositories\ContactRepository.cs:line 78
at RuleEngine.API.Jobs.ProcessRules.ProcessContactRules.BeginJob(Guid organizationId) in C:\Users\dthk\Source\Repos\AdvocacySolutions\RuleEngine.BackgroundTasks\Application\Jobs\ProcessRules\ProcessContactRules.cs:line 40
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Issue Analytics
- State:
- Created 4 years ago
- Comments:14 (7 by maintainers)
I have a key milestone coming up and had to leverage my hack/fix. I should be able to test and provide feedback in the next day or so.
Great debugging and very interesting. While it is interesting that using
Lazy
is the way the ASP.NET team went, it feels a little hacky to me.Instead, I might look at changing a bit internally of how the locking system I already use works (the
ReadWriteSlim
used to work around problems in the MongoDB driver).I’m thinking maybe having an
EntityMapping.TryRegister
method used for cases like that instead. Would be quite similar toGetOrCreate
though instead of returning the definition, it just returns true/false.I’ll try and get this done over the next few days.