-
Type: Bug
-
Resolution: Fixed
-
Priority: Unknown
-
Affects Version/s: None
-
Component/s: None
-
None
-
Fully Compatible
-
Not Needed
-
Summary
I found a case in which using AsQueryable() throws NRE. Driver version: 2.19.1.
How to Reproduce
I have this model:
class Model { public Guid NotId { get; set; } public string Name { get; set; } }
The query is:
var collection = database.GetCollection<Model>("models"); var query = await collection.AsQueryable() .GroupBy(x => x.Name) .Select(x => new Model { NotId = Guid.Empty, Name = x.Key }) .ToListAsync(); // throws NRE
Additional Background
I am using V3 guid serialization:
BsonDefaults.GuidRepresentationMode = GuidRepresentationMode.V3; BsonSerializer.RegisterSerializer(new GuidSerializer(GuidRepresentation.Standard));
Workarounds
I found two workarounds:
- Modify the projection to return anonymous type instead of Model
- Change the return type of Model.NotId to Guid?