[CSHARP-351] Better error message when document being deserialized doesn't match class declaration Created: 03/Nov/11  Updated: 02/Apr/15  Resolved: 04/Nov/11

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

Type: Improvement Priority: Minor - P4
Reporter: Robert Stam Assignee: Robert Stam
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Minor Change

 Description   

Given the following classes:

public class C

{ public int _id; public N n; }

public class N

{ public int x; }

the following code results in an InvalidOperationException:

var json = "

{ '_id' : 1, n : 'should be a document, not a string' }

";
BsonSerializer.Deserialize<C>(json);

The error message should be more specific, identifying which property of which class couldn't be deserialized.



 Comments   
Comment by auto [ 16/Jul/12 ]

Author:

{u'date': u'2012-07-16T05:59:09-07:00', u'email': u'robert@10gen.com', u'name': u'rstam'}

Message: CSHARP-351: Make settings classes more robust by adding some checks for nulls. Protect Servers property of MongoServerSettings from modification. Fixed some bugs in MongoGridFSSettings.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/a5094971192c41df392d4c6d6f20d68a7dd129a2

Comment by Robert Stam [ 04/Nov/11 ]

When the BsonClassMapSerializer encounters an error deserializing a field or property the name of the field or property as well as the name of the class they are in are included in the error message to assist the user in troubleshooting the problem.

Backward breaking in the sense that the type of the exception thrown is sometimes different.

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