简体   繁体   中英

BSON Serialization Exception on insert. c#

i have this BsonDocument that i'm trying to insert with insertOneAsync :

{{
    "starttime": "05.11.2003 17:29:35.189",
    "clk": "0.01",
    "frames": "000001328",
    "typ": "real",
    "MasterRev": "19",
    "WriterVer": "3.0.85",
    "ClientKey": "B4B18CC22F9A4F82FA4D975B53933B5A",
    "Start": "11/05/2003 17:29:35",
    "ID": "File2",
    "InfoCustomEntryA": "AAA0",
    "InfoCustomEntryB": "B1",
    "InfoCustomEntryC": "Just A Standard Entry For The Cold Mill",
    "module_name_0": "RealSignals",
    "module_name_1": "RealSignals5x",
    "module_name_2": "IntegerSignals",
    "module_name_3": "IntegerSignals6x",
    "ibaFilesTest": "12/4/2015 11:46:10 AM",
    "ibaFiles": "6.3.2 Lite (update)",
    "$DATCOOR_status": "processed",
    "$DATCOOR_OutputFiles": "",
    "$DATCOOR_times_tried": "1",
    "$DATCOOR_TasksDone": ""
}
}

Getting MongoDB.Bson.BsonSerializationException in MongoDB.Driver.Core.dll

How can I debug this?

Had to ignore the meta data when i serialized. The following works.

{{
    "starttime": "05.11.2003 17:29:35.189",
    "clk": "0.01",
    "frames": "000001328",
    "typ": "real",
    "MasterRev": "19",
    "WriterVer": "3.0.85",
    "ClientKey": "B4B18CC22F9A4F82FA4D975B53933B5A",
    "Start": "11/05/2003 17:29:35",
    "ID": "File2",
    "InfoCustomEntryA": "AAA0",
    "InfoCustomEntryB": "B1",
    "InfoCustomEntryC": "Just A Standard Entry For The Cold Mill",
    "module_name_0": "RealSignals",
    "module_name_1": "RealSignals5x",
    "module_name_2": "IntegerSignals",
    "module_name_3": "IntegerSignals6x",
    "ibaFilesTest": "12/4/2015 11:46:10 AM",
    "ibaFiles": "6.3.2 Lite (update)"
}
}

How can I debug this?

Try placing a try-catch block around your call to InsertOneAsync , like so:

try
{
    YourMongoCollectionHere.InsertOneAsync(YourBsonDocumentHere);
}
catch (MongoException e)
{
    // examine your exception 'e' here
}

您需要删除多余的花括号以获取有效的JSON,但是,更重要的是Mongo不允许以$开头的字段名称,请参见JIRA票证。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM