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

Postpone creation of serializers until they are first needed

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • 1.8
    • Affects Version/s: 1.7
    • Component/s: None
    • Environment:
      Windows 8
    • Major Change

      In March 2012, https://github.com/g0t4/mongo-csharp-driver/commit/1ad28750b052a8c6f789d39c6d522798c0aafc46, the driver was updated to clone & freeze default options in BsonBaseSerializer's constructor. As a result, any calls to several static constructors in the API will trigger this and freeze the default options at that point in time for DictionarySerializationOptions and DateTimeSerializationOptions. It's very easy to accidentally trigger and in some cases hard to avoid when re-using modules that depend on mongodb that have their own initialization that might trigger it as well. I have a patch request coming from GitHub.

      If clone & freeze is left, this should be reflected with exceptions in the defaults API (DateTimeSerializationOptions.Defaults), but even doing that would cause issues when modules trigger the Clone & Freeze, so I would suggest Freezing be a feature the consumer can request if desired and not forced on them via the driver and Clone should be removed.

      IMO, the best fix would be to refactor the configuration of serialization (primarily BsonSerializer) to be contextual and not static, this way different modules can operate in the same process and not stomp on each other's configuration. This could be passed into a new MongoDatabase and forwarded to MongoCollection instances.

      [Edited by Robert Stam]:

      See the comment added 11/29 describing the actual change made to address setting default options for serializers. The summary of the issue has also been edited to reflect that.

      To summarize the changes:

      • we are deprecating almost all the static Instance properties
      • we are deprecating the XyzSerializationOptions.Defaults properties
      • the recommended way to set the defaults is now to create a serializer with the desired defaults and register it
      • the default serialization provider now creates serializers as late as possible so if you do set the deprecated Defaults properties they will be used (but they will be removed in 2.0)

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            wes.mcclure@gmail.com Wesley McClure
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: