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

Make BsonSerializerRegistry.RegisterSerializer idempotent

    XMLWordPrintableJSON

Details

    • Icon: Improvement Improvement
    • Resolution: Won't Fix
    • Icon: Minor - P4 Minor - P4
    • None
    • None
    • None
    • None
    • MongoDB Driver 2.5
    • Fully Compatible

    Description

      Right now, if I register the same BsonSerializer twice, I'll get an exception saying that a BsonSerializer has already been registered for that type.

      I'm running my tests using XUnit, and a few of them pass through the part of my project that registers a couple of custom serializers. Even though each only passes through this code once, when ran together, the static nature of BsonSerializer somehow causes them to interfere with each other, throwing the "There is already a serializer registered for type ..." exception (thrown here).

      It seems that the API would be more developer friendly if this method would allow the same serializer to be registered twice. A potential fix would be to, if failing to add it to the dictionary, check if it already exists in the dictionary, and, if so, do nothing (instead of throwing).

      I'm happy to do a pull request if necessary.

      Attachments

        Activity

          People

            vincent.kam@mongodb.com Vincent Kam (Inactive)
            Yax Josh Yaxley [X]
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: