为 DotNet Core 使用 MongoDB 驱动程序时出现异常

Exception occurs when using MongoDB driver for DotNet Core

我正在研究以下堆栈的解决方案:

...使用此驱动程序与数据库通信:https://www.nuget.org/packages/MongoDB.Driver.Core/ ...版本 2.4.1

我正在尝试像这样实例化 MongoClient:

var options = provider.GetService<IOptions<MongoDbSettings>>();
var client = new MongoClient(options.Value.ConnectionString);

但是最后一条语句出错了:

An exception of type 'System.MissingMethodException' occurred in MongoDB.Driver.dll but was not handled in user code

Additional information: Method not found: 'Void MongoDB.Driver.ReadPreference..ctor

我注意到 class MongoClient 在 MongoDB.Driver 命名空间中,而不是在 MongoDB.Driver.Core 中。 这是否意味着它与 .Net Core 不兼容? 如果是这样,我该如何连接到数据库?

感谢所有帮助!

此致, 乔恩

我最终使用了这个驱动程序: http://mongodb.github.io/mongo-csharp-driver/

版本2.3.0,解决了问题。