Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-4272

Validate return value of bsonClassMap.CreateInstance() in BsonClassMapSerializer

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Unknown Unknown
    • 2.18.0
    • 2.17.0
    • None
    • None

    Description

      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(); 

       

       

       

      Attachments

        Activity

          People

            boris.dogadov@mongodb.com Boris Dogadov
            mspreafico@gmail.com Matteo Spreafico
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: