Problems with mongo csharp driver version

3

I use the mongo csharp driver version 1.9.1. But, I have a problems with this dll. The exception is:

"Could not load file or assembly 'MongoDB.Bson, Version=1.9.1.221, Culture=neutral, PublicKeyToken=f686731cfb9cc103' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)":"MongoDB.Bson, Version=1.9.1.221, Culture=neutral, PublicKeyToken=f686731cfb9cc103".

Does anybody have any suggestion ?

Thanks a lot in advance

mongodb
mongodb-.net-driver
asked on Stack Overflow Jun 18, 2014 by Dhibi_Mohanned

3 Answers

3

I was having the same problem, this error occurs due to conflict you may have added more than one reference to MonogoDb in your Solution. Solution: If there are more than one project in your solution remove MongoDb references from all project and then add to only one project that is dependent on all other projects. It worked for me.

answered on Stack Overflow Apr 8, 2015 by Amanullah Tariq
2

To build on Amanullah Tariq's answer; You may have more than one project referencing MongoDb or its drivers, HOWEVER; [solution] make sure that each project make use of the same version. That was what was causing my error. If the versions are not the same, make sure to either upgrade or downgrade the versions to match. I hope this helps any one struggling with this issue in the future.

answered on Stack Overflow Feb 18, 2016 by onmyway
0

For me, it was not possible to remove the MongoDB references from all the projects and refer to single project, as it's a utility solution and works on different .net frameworks and .net core versions.

So, I have updated the mongodb driver for the project using nuget and it worked.

Other projects are also working fine. As, MongoDB Drivers gets the reference from the common place.

Before Update of nuget:

enter image description here

After Update of nuget:

enter image description here

If any of the project fails then just update MongoDB.Driver version to the latest.

For .Net Framework:

Check your packages.config file, It will be something like this (sample for 4.7.2 framework):

<package id="MongoDB.Driver" version="2.12.0" targetFramework="net472" />

For .Net Core: check in .csproj file in <ItemGroup>. Something like this:

<ItemGroup>
   ...... // other are deleted just to focus on main part
   <PackageReference Include="MongoDB.Driver" Version="2.12.0" />
</ItemGroup>
answered on Stack Overflow Mar 15, 2021 by KushalSeth • edited Mar 15, 2021 by KushalSeth

User contributions licensed under CC BY-SA 3.0