[CSHARP-1339] Adding array member to collection model causes error during subsequent deserialisation Created: 28/Jun/15 Updated: 02/Apr/20 Resolved: 02/Apr/20 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | Serialization |
| Affects Version/s: | 2.0.1 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Minor - P4 |
| Reporter: | Kieren Johnstone | Assignee: | Wan Bachtiar |
| Resolution: | Done | Votes: | 6 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||
| Description |
|
Types:
Code:
The exception: "No matching creator found." (BsonSerializationException), from BsonClassMapSerializer.ChooseBestCreator. The reason: Here's the server command:
The response:
Basically, the array part of the projection comes back as an empty document when it doesn't exist, as would be the case when the member is new. BsonClassMapSerializer.DeserializeClass() doesn't populate any values from it of course, and no missing values are populated because the array member is marked IsReadOnly. In ChooseBestCreator, the MostArgumentsCreatorSelector() looks for an appropriate creator, but with no values it can't determine one. I'm not 100% on what the bug is, but perhaps - looking at DeserializeClass() - MemberMap.IsReadOnly for the array property of the projection should not be null, or should not be checked for null when dealing with missing values? (Marking as minor since I'm not sure if the deserialisation code should be expected to deal with whatever crazy cases might be thrown at it like this) |
| Comments |
| Comment by Robert Stam [ 19/Jun/19 ] | |||||||||||||||||
|
The issue is not so much that an array was added to the data model, but that the automatically created serializer for an anonymous type does not allow missing elements. I've created a new linked ticket for the underlying anonymous type serialization issue. | |||||||||||||||||
| Comment by Kevin Fairs [ 04/Apr/19 ] | |||||||||||||||||
|
Just hit this in v.2.8.0. Do these ever get fixed? | |||||||||||||||||
| Comment by Andrey Kalinin [ 18/Dec/17 ] | |||||||||||||||||
|
I have this problem too.
This code throw BsonSerializationException after add new boolean field "IsFree". | |||||||||||||||||
| Comment by Micha? D?biec [ 27/Oct/16 ] | |||||||||||||||||
|
I have also expirienced this issue in following case: My class has Description property:
Due to BsonIgnoreIfDefault attribute null values are not stored in database (this is nice). Description property is not present in some documents.
Than i run the query with projection:
Iterating over result crashes with: MongoDB.Bson.BsonSerializationException: No matching creator found. I can probably do not use BsonIgnoreIfDefault attribute in my model and reinsert/update the data, so the problem will be temporairly solved, but it will come back when the model grows (new properties will be added in future). Plase fix it somehow. | |||||||||||||||||
| Comment by Alexey [ 03/Jun/16 ] | |||||||||||||||||
|
We faced this bug too, it prevents us from using dynamically composed .Select on some dictionary styled fields. Can this please be fixed? | |||||||||||||||||
| Comment by Kieren Johnstone [ 28/Jun/15 ] | |||||||||||||||||
|
It looks like the creator isn't matched because there's no default value for the member of the anonymous type. No value and no default = it thinks it can't proceed. I have a solution - would like to check its validity: BsonCreatorMap.Freeze() - populates the default value for that map. Removing the check to see if the default value has been specified -
The
|