MongoDB - 'MongoDB.Bson.ObjectId' 的类型初始值设定项引发异常 [英] MongoDB - The type initializer for 'MongoDB.Bson.ObjectId' threw an exception

查看:145
本文介绍了MongoDB - 'MongoDB.Bson.ObjectId' 的类型初始值设定项引发异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想知道是否有人见过这个例外?我正在使用 C# 驱动程序并已在许多服务器上成功运行此代码.我们在一台特定的生产服务器上看到了这一点.

I'm just wondering if anyone has ever seen this exception? I'm using the C# driver and have successfully run this code on many servers. We are seeing this on one particular production server.

我第一次看到这是在第一次插入新集合时.之后,每次我为该集合调用 InsertBatch 时似乎都会发生这种情况.

The first time I see this is on the first insert into a new collection. After that it seems to occur each time I call InsertBatch for that collection.

我在同一次运行中成功地对其他集合调用了 InsertBatch.

I've successfully called InsertBatch on other collections successfully during the same run.

Error** Message = 'MongoDB.Bson.ObjectId' 的类型初始值设定项引发异常.,Stack Trace = at MongoDB.Bson.ObjectId.GenerateNewId()在 MongoDB.Bson.Serialization.IdGenerators.BsonObjectIdGenerator.GenerateId(对象容器,对象文档)在 MongoDB.Driver.MongoCollection.InsertBatch(类型标称类型,IEnumerable 文档,MongoInsertOptions 选项)

Error** Message = The type initializer for 'MongoDB.Bson.ObjectId' threw an exception., Stack Trace = at MongoDB.Bson.ObjectId.GenerateNewId() at MongoDB.Bson.Serialization.IdGenerators.BsonObjectIdGenerator.GenerateId(Object container, Object document) at MongoDB.Driver.MongoCollection.InsertBatch(Type nominalType, IEnumerable documents, MongoInsertOptions options)

谢谢,

保罗

推荐答案

有趣的是 BsonId 序列化已经在 2013 年从某人那里实现了https://github.com/SharpRepository/SharpRepository/issues/56

It is interesting with BSonId serialization which has implemented at 2013 from someones https://github.com/SharpRepository/SharpRepository/issues/56

就我而言,将 Asp.net Core 3.0 降级到 2.2 已经解决了.

In my case downgrading Asp.net Core 3.0 to 2.2 has worked out.

我认为 mongodb.csharp 驱动需要 System.Runtime.Serialization.Formatters 参考

I think mongodb.csharp driver needs to System.Runtime.Serialization.Formatters reference

3.0 版本

https://github.com/dotnet/core/issues/2611

更新将在 2019 年的第二个单独发布https://github.com/mongodb/mongo-csharp-driver/pull/372

And an update will come on second separate of 2019 https://github.com/mongodb/mongo-csharp-driver/pull/372

这篇关于MongoDB - 'MongoDB.Bson.ObjectId' 的类型初始值设定项引发异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆