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

MongoDB.Bson.BsonSerializationException (when serializing List of MongoDBRef)

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Unknown Unknown
    • 2.22.0
    • None
    • None
    • None
    • Fully Compatible
    • Not Needed
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?

    Description

      Using MongoDB Driver version 2.19

      The error (MongoDB.Bson.BsonSerializationException: 'An error occurred while serializing the students property of class PatientJourney.ExamModel: Element name '$ref' is not valid'.') is thrown when calling the method _collection.ReplaceOneAsync(filter,model) with students.length >1 which dataType is List<MongoDBRef>.

      The error is not thrown when using the method _collection.InsertOneAsync(model) and when the length of the MongoDBRef List is not larger than 1 in the _collection.ReplaceOneAsync(filter,model) method. Note that the same model is passed to InsertOneAsync method and ReplaceOneAsync method

      Attachments

        Activity

          People

            oleksandr.poliakov@mongodb.com Oleksandr Poliakov
            thomasleung1234@gmail.com Lok Fung Leung
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: