bson serialization issue with driver upgrade ( System.IO.FileFormatException: Unexpected element: value )

95 views
Skip to first unread message

Alex K

unread,
Apr 15, 2011, 1:57:31 PM4/15/11
to mongodb-user
I upgraded the driver to both 1.0 and the latest commit today. Both
versions give me the following errors: http://paste.ly/6hzy

With the older .9 version of the driver we didn't have these issues.
Was there some breaking change that we need to support?

Thanks,
Alex

Robert Stam

unread,
Apr 15, 2011, 2:07:59 PM4/15/11
to mongodb-user
There are some minor changes, but I can't tell if they are the cause
of what you are seeing or not.

The error message is saying that in the process of deserializing a
BSON document it found an unexpected element called "value" (meaning
that the class you are deserializing into doesn't have a matching
property).

Can you post the class declaration for the document you are
deserializing? Also, can you display the document that is giving you
this error in the mongo shell and post it here also? By comparing the
two we can figure out why you are getting this exception.

Alex K

unread,
Apr 15, 2011, 2:24:59 PM4/15/11
to mongodb-user
Thanks Robert, I posted this issue with the data you requested in the
official support: https://jira.mongodb.org/browse/CS-499

Robert Stam

unread,
Apr 15, 2011, 2:49:20 PM4/15/11
to mongodb-user
OK. Following up on JIRA.

Robert Stam

unread,
Apr 15, 2011, 3:59:11 PM4/15/11
to mongodb-user
Here's a summary of what happened and how to avoid it:

The code that was failing was using FindAndRemove and attempting to
deserialize the modified (removed) document. The return value of
FindAndRemove is of type FindAndModifyResult, which in turn is a
subclass of CommandResult;

In the v1.0 driver CommandResult is no longer a subclass of
BsonDocument. Instead it has a property called Response of type
BsonDocument that contains the raw response from the server, and it
contains two elements: "value" and "ok". If you try to deserialize the
Response property into a C# class you get an exception because the
"value" element has no corresponding property in the C# class.

The ModifiedDocument property has the actual modified document itself
(the value of the "value" element). So it's the ModifiedDocument that
should be deserialized and not the Response.

There is also a method called GetModifiedDocumentAs<T> that will do
the deserialization for you.
Reply all
Reply to author
Forward
0 new messages