Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

838
Views
C# .Net + MongoDB Atlas connection string MongoDB.Driver.Legacy error when trying to run Client

I've set up a Cluster + Collection in a MongoDB Atlas database. I'm trying to follow tutorials such as this one: Bookstore | Using ASP.NET Core 5.0 and MongoDB

my code is as follows, with <> replaced with real data of course:

var client = new MongoClient("mongodb+srv://<username>:<password>@<clustername>.ck3ra.mongodb.net/<database>?retryWrites=true&w=majority");
var database = client.GetDatabase("<database>");
var collection = database.GetCollection<BsonDocument>("validation");
ShowMessage(collection.ToString());

The error i'm getting is:

System.IO.FileLoadException: Could not load file or assembly 'MongoDB.Driver.Legacy' or one of its dependencies. An argument was out of its legal range. (Exception from HRESULT: 0x80131502) File name: 'MongoDB.Driver.Legacy' ---> System.ArgumentOutOfRangeException: Length cannot be less than zero. Parameter name: length

I'm not sure what's wrong here because I am writing the connection string exactly as per the Connect instructions on the MongoDB website, as well as the other tutorials...

Would appreciate any help on this. Thanks.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You need to make sure that your have added the mongocsharpdrive package to your package and it’s dependencies. As you are targeting to .net5 so please consider the .net standard 2.0 dependencies.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!