Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exception occurs when using MongoDB driver for DotNet Core

I'm working on solution on the following stack:

  • ASP.NET Core
  • .NET Core
  • MongoDB

...using this driver for communication with the database: https://www.nuget.org/packages/MongoDB.Driver.Core/ ...version 2.4.1

I'm trying to instantiate the MongoClient like this:

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

But the last statement errors out saying:

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

and

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

I've noticed that the class MongoClient is in the MongoDB.Driver -namespace, not in MongoDB.Driver.Core. Does that mean it is not compatible with .Net Core? If so, how do I then connect to the database?

All help appreciated!

Regards, Jon

like image 407
YonZo Avatar asked Oct 22 '25 00:10

YonZo


1 Answers

I ended up using this driver: http://mongodb.github.io/mongo-csharp-driver/

version 2.3.0, which solved the problem.

like image 59
YonZo Avatar answered Oct 23 '25 20:10

YonZo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!