I am getting error \"Cannot deserialize string from BsonType ObjectId\"
while trying to get all the record from MongoDb in C# WebAPI
My Id is
Guid.NewGuid() will not produce ObjectId. Object Id is 12 byte data structure and Guid produce 16byte hex string (without '-')
You should remove attribute [BsonRepresentation(BsonType.ObjectId)]
You can use any string as Id in your entity for example 'HiDude' and any string in utf8 format.
Instead of using
ed.Id = Guid.NewGuid().ToString();
I used
ed.Id = MongoDB.Bson.ObjectId.GenerateNewId().ToString();
For generating Id
Its working fine : )