I am a new comer to MongoDb and I am presently while using CSharp motorists (version 1.2). My problems occur when utilizing BsonClass map. Below may be the code I am tring to complete. I have simply defined a custom type Let me map to some BsonDocument.

To be able to make use of this I am benefiting from BsonClassMap.RegisterClassMap(). After I hit the foreach statement (attempting to access the very first entry within the FinAs() results) I recieve the next error:

'Cannot deserialize Guid from BsonType ObjectId.'

From things i understand BsonClassMap uses GuidGenerator for objects of type Guid. Why shall we be held getting this error?

Please be aware the insertion is carried out with no errors...and after carrying out the place, newEmployee comes with an EmployeeId which has been instantly produced for this.

Here's the code I am attempting to run:

     class Program{

        static void Main(string[] args){

            MongoServer server = MongoServer.Create();

            MongoDatabase dataBase = server.GetDatabase("test");

            MongoCollection<Employee>employees = dataBase.GetCollection<Employee>("employees");

            BsonClassMap.RegisterClassMap<Employee>(cm =>
                                                        cm.MapProperty(c => c.Name);
                                                        cm.MapProperty(c => c.Email);
                                                        cm.MapIdProperty(c => c.EmployeeId);

            var newEmployee = new Employee{ Name="Test", Email="test@test.com"}; 


            foreach(Employee e in employees.FindAs<Employee>(Query.EQ("Name","Test")){




     public class Employee
         public Guid EmployeeId {get;set;}
         public string Name {get;set;}
         public string Email {get;set;}

I suspect you should utilize SetIdMember to recognize your id area. Any particular reason you are not using ObjectId values rather than Guids?