I am in Mongo-C# environment and using 10Gen Mongo driver. i am facing a problem when I am trying to deserialize the data inside the Mongo document when it has a sub document and that sub document is not strongly typed. In other words, if the sub document is an Expando or simply an anonymous object() then it give errors out while deserializing with the following error:
System.IO.FileFormatException: A document being deserialized to
System.Object must be empty.
We I can put a filter before and after the Mongo read/write which converts my Object into a BSONDocument on the fly but I think there is not cast available between BSOnDocument and (Expando or anonymous type).
Writting a custom deserialization tool sounds like too much work for this. I am just wondering is someone has faced this problem before and how they have handled this problem?
Currently, since the 10gen driver is based on .NET 3.5, we do not support dynamic objects. Currently, the way to handle this is using an ExtraElements member. You can read about it here: http://www.mongodb.org/display/DOCS/CSharp+Driver+Serialization+Tutorial#CSharpDriverSerializationTutorial-Supportingextraelements.
We will be supporting .NET 4.0 in full at a later date and with that will come full support for dynamic objects. If you really need the feature now, you can see my spike of side-by-side support using another assembly here: https://github.com/craiggwilson/mongo-csharp-driver/tree/dynamic. However, it is untested and is truly just a spike, so be wary.