Validate return value of bsonClassMap.CreateInstance() in BsonClassMapSerializer

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Done
    • Priority: Unknown
    • 2.18.0
    • Affects Version/s: 2.17.0
    • Component/s: None
    • None
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Summary

      BsonClassMapSerializer throws a NullReferenceException when BsonClassMap::CreateInstance() returns null, which may happen if one has configured a creator on the map and that creator fails silently returning nulls instead of object instances (think of DI containers)

      How to Reproduce

      Simulate a failing creator:

      BsonClassMap .LookupClassMap(typeof(MyModel)) .SetCreator(() => {
      //could be something like:
              //ServiceProvider.GetService(domainObjType)
      
              //that may...
              return null;
      }); 

      Execute a Find() on that type:

      var filter = SetupTheFilterDefinition();
      var results = collection.Find<MyModel>(filter).ToList(); 

       

       

       

              Assignee:
              Boris Dogadov
              Reporter:
              Matteo Spreafico
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: