Serialization of a C# class that uses [BsonRepresentation] attributes.

678 views
Skip to first unread message

S Sireesha

unread,
Aug 26, 2014, 7:58:50 PM8/26/14
to mongod...@googlegroups.com
Hi

The project I am working on has multiple C# classes which use [BsonRepresentation] attributes for their properties (mostly for Enum types in order to write values as strings in mongo).
I am trying to write tests for these classes that ensure that the Bson representation of the class is as expected. I want to do this by serializing the class to Bson and comparing the resultant string/document with a predefined string.

I tried different versions of  BsonSerializer.Serialize, BsonDocumentWrapper.Create and <MyClass>.ToBson() but all attempts throw this exception:

An exception of type 'System.NotSupportedException' occurred in MongoDB.Bson.dll but was not handled in user code
Additional information: A serialization options attribute of type BsonRepresentationAttribute cannot be used when the serializer is of type BsonClassMapSerializer.

Any suggestions?

Thanks!

craiggwilson

unread,
Aug 27, 2014, 7:46:07 PM8/27/14
to mongod...@googlegroups.com
Sorry you're having some trouble. To help, we really examples of your classes so we can reproduce what is going on.

Craig
Reply all
Reply to author
Forward
0 new messages