Cannot deserialize string from BsonType ObjectId.

6,094 views
Skip to first unread message

chang

unread,
Mar 29, 2012, 9:38:19 PM3/29/12
to mongodb-user
The official drives (C sharp)

class name is WorkOrderInfo

private string Tx_ID;//ID
/// <summary>
/// ID
/// </summary>
[BsonId(IdGenerator = typeof(StringObjectIdGenerator))]
public string ID
{
get { return Tx_ID; }
set { Tx_ID =value; }
}

An error occurred while deserializing the ID property of class
WorkOrderInfo: Cannot deserialize string from BsonType ObjectId.

Robert Stam

unread,
Mar 29, 2012, 10:14:48 PM3/29/12
to mongod...@googlegroups.com
Which version of the C# driver are you using?


--
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com.
To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.


Robert Stam

unread,
Mar 29, 2012, 11:45:43 PM3/29/12
to mongod...@googlegroups.com
If you look at your collection I think you will find that some documents have an ObjectId value for the _id, but your class declares ID to be a string.

What are you trying to accomplish?

chang

unread,
Mar 30, 2012, 2:22:29 AM3/30/12
to mongodb-user
c# driver version:1.4.0.4468

yes,i do

Robert Stam

unread,
Mar 30, 2012, 9:38:30 AM3/30/12
to mongod...@googlegroups.com
If you have documents that don't match your class declaration you will need to clean up your database first.

Still not sure what you are trying to accomplish, though. Your usage of the StringObjectIdGenerator is rather unusual. Why don't you just store your Ids as ObjectIds?

On Fri, Mar 30, 2012 at 2:22 AM, chang <4216...@qq.com> wrote:
c# driver version:1.4.0.4468

yes,i do
Reply all
Reply to author
Forward
0 new messages