c# - System.FormatException' occurred in MongoDB.Bson.dll - XXX is not a valid 24 digit hex string -
i have created c# class this:
public class employee { [bsonrepresentation(bsontype.objectid)] public string name { get; set; } public int age { get; set; } public list<string> address { get; set; } }
when try save information (using mongodb) this:
var e = new employee(); e.address = new list<string>(); e.address.add("address 1"); e.address.add("address 2"); e.age = 333; e.name = "some name"; context.employees.insert(e);
i getting following error:
an unhandled exception of type 'system.formatexception' occurred in mongodb.bson.dll additional information: 'some name' not valid 24 digit hex string.
how can make string field act objectid
in mongodb?
reading docs:
... in case serializer convert objectid string when reading data database , convert string objectid when writing data database (the string value must valid objectid) ....
please remove white space string. should work!
to proof wether have valid objectid, read following so-post: mongodb node check if objectid valid
edit: final answer was: you have change [bsonrepresentation(bsontype.objectid)] [bsonid]
Comments
Post a Comment