[CSHARP-1258] Sometimes the driver reports: BsonSerializationException Created: 27/Apr/15  Updated: 05/Apr/16  Resolved: 17/Jun/15

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

Type: Bug Priority: Critical - P2
Reporter: John Cheng Assignee: Craig Wilson
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Windows


Attachments: Text File BsonException.txt     Text File QueryMongo.txt    

 Description   

We insert two types of data to mongodb: AaaChange and InferredChange. They both are derived from the base type Change. But when we query them out occasionally we get error: Unknown discriminator value 'InferredChange'. Attached are the code we used to query mongodb and the exception stack.



 Comments   
Comment by Craig Wilson [ 27/Apr/15 ]

Hi John,

It is important when working with discriminated types that they are all registered before their use. For instance, if you try and run a query that returns an InferredChange instance before the driver is aware of the InferredChange type, we don't know how to instantiate it.

Have a read of the documentation here: http://mongodb.github.io/mongo-csharp-driver/1.10/serialization/#polymorphic-classes-and-discriminators

Please let me know if this fixes your issue.
Craig

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