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

BsonDocument.DeepClone() fails on documents with duplicate element names

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor - P4 Minor - P4
    • None
    • 2.7.0
    • BSON
    • None
    • All
    • Minor Change

    Description

      The following code fails:

      var doc = new BsonDocument() { AllowDuplicateNames = true };

      doc.Add("a", 1);

      doc.Add("a", 2);

      var doc2 = doc.DeepClone();

       

      This is because DeepClone does:

      {{ BsonDocument clone = new BsonDocument();}}
      {{ foreach (BsonElement element in _elements)}}
      {{ {}}
        clone.Add(element.DeepClone());
      {{ }}}
      {{ return clone;}}

      Changing the first line to:

      BsonDocument clone = new BsonDocument() { AllowDuplicateNames = AllowDuplicateNames };

      fixes the problem.

       

      Attachments

        Activity

          People

            Unassigned Unassigned
            admilazz Adam Milazzo
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: