[CSHARP-4675] Ignore __safecontent__ field in deserialization Created: 09/Jun/23  Updated: 28/Oct/23  Resolved: 02/Aug/23

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

Type: Task Priority: Minor - P4
Reporter: Mike Woofter Assignee: Boris Dogadov
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

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   

Summary

When you insert a document into an encrypted collection, the safeContent field is automatically added. (This field is necessary for QE to work.) If you attempt to then find that document and let the driver automatically deserialize it to a POCO you've defined, the driver throws an exception:

Unhandled exception. System.FormatException: Element 'safeContent' does not match any field or property of class <your POCO class>.

I was able to avoid this error by adding theĀ 
[BsonIgnoreExtraElements] attribute to my POCO class, but it would be nice if the driver were aware that it should ignore that field.

Motivation

Who is the affected end user?

Anyone using the C# driver for QE with POCOs

How does this affect the end user?

Throws an exception if the attribute is not added

How likely is it that this problem or use case will occur?

Assuming most users use POCOs, this is a main path error

If the problem does occur, what are the consequences and how severe are they?

The app doesn't work without the attribute

Is this ticket required by a downstream team?

No

Is this ticket only for tests?

No

Acceptance Criteria

Ideally, I wouldn't need to add this attribute to the class in order for QE to work with POCOs. If that's not possible, we can discuss documenting this requirement somewhere.



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

Author:

{'name': 'BorisDog', 'email': 'BorisDog@users.noreply.github.com', 'username': 'BorisDog'}

Message: CSHARP-4675: Ignore _safecontent_ field in deserialization (#1150)
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/59eb17e361b2354e0e213b636130e58261ddeb79

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