[CSHARP-4756] MongoDB.Bson.BsonSerializationException (when serializing List of MongoDBRef) Created: 17/Aug/23  Updated: 28/Oct/23  Resolved: 13/Sep/23

Status: Closed
Project: C# Driver
Component/s: None
Affects Version/s: None
Fix Version/s: 2.22.0

Type: Bug Priority: Unknown
Reporter: Lok Fung Leung Assignee: Oleksandr Poliakov
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible
Documentation Changes: Not Needed
Documentation Changes Summary:

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



 Comments   
Comment by Githook User [ 30/Aug/23 ]

Author:

{'name': 'Oleksandr Poliakov', 'email': '31327136+sanych-sun@users.noreply.github.com', 'username': 'sanych-sun'}

Message: CSHARP-4756: MongoDB.Bson.BsonSerializationException (when serializing List of MongoDBRef) (#1167)
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/6042afc4ae9323d462c4cb3c35877a6da8fcc477

Comment by PM Bot [ 17/Aug/23 ]

Hi thomasleung1234@gmail.com, thank you for reporting this issue! The team will look into it and get back to you soon.

Generated at Wed Feb 07 21:49:16 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.