Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

847
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda