Particular / NServiceBus.Storage.MongoDB

NServiceBus MongoDB persistence
Other
4 stars 6 forks source link

Updating MongoDB.Driver to 2.28.0 version breaks the MongoClient #660

Open SpartaDeveloper93 opened 1 month ago

SpartaDeveloper93 commented 1 month ago

Describe the bug

Description

We are using MongoDB for our Outbox Persistence and recently decided to update our MongoDB.Driver to latest version which is 2.28.0. As per the package dependencies of this library's version 4.0.0, it should have been compatible but results in build time error.

Expected behavior

Updating the MongoDB.Driver should not result in any code changes or build errors.

Actual behavior

The application starts throwing the following error during build:

Error CS0012 : The type 'IMongoClient' is defined in an assembly that is not referenced. You must add a reference to assembly 'MongoDB.Driver, Version=2.24.0.0, Culture=neutral, PublicKeyToken=null'.

Versions

NService.Storage.MongoDB -> 4.0.0 Please list the version of the relevant packages or applications in which the bug exists.
NServiceBus -> 9.0.1

Steps to reproduce

  1. Install NService.Storage.MongoDB version 4.0.0
  2. Install MongoDB.Driver version 2.28.0
  3. Add the endpoint with Outbox and MongoDB as persistence.
  4. Build Error will come up.

Relevant log output

No response

Additional Information

Workarounds

So, our workaround for this has been to use the below line in our PackageReference which resolved the issue for the time being: <PackageReference Include="MongoDB.Driver" Version="[2.24.0, 2.28.0]"/>

Possible solutions

Additional information

johnsimons commented 1 month ago

Hi @SpartaDeveloper93,

Sorry that this is causing issues for you. I am trying to reproduce this issue, but I am unable to do so. I've downloaded the MongoDB sample we have, and it seems it builds fine with v2.28.0. image

Are you able to have a look at that sample and tell us what we need to modify to reproduce the issue?

SpartaDeveloper93 commented 1 month ago

@johnsimons

For the MongoDB database, you need to use the following lines

var persistence = endpointConfiguration.UsePersistence<MongoPersistence>(); persistence.MongoClient(new MongoClient( <MongoDbConnectionString> )); persistence.DatabaseName( <DatabaseName> );

The error comes on this line:

persistence.MongoClient(new MongoClient( <MongoDbConnectionString> ));

johnsimons commented 1 month ago

Hi @SpartaDeveloper93,

So we have investigated what the issue is with this, and it gets pretty interesting. So it seems the version 2.28.0 of the MongoDB.Driver library is now strong name (Yes I know, I thought strong name in dotnet world was not a thing anymore!) image As far as we understand, this seems to cause this issue. If you instead reference v2.27.0 or any other version before 2.28.0 it does work!

This has implications as pointed out by you, if a new version of MongoDB.Driver is released to patch for example, a CVE, the customers won't be able to patch it directly in their code and need to wait for the 3rd party (in this case Particular) to upgrade their library to reference the patched version 😞

So, we are planning to touch basis with the MongoDB driver authors and point this out. In the meantime, we are trying to figure out if there are any workarounds and we will let you know what the outcome is.

I hope this makes sense.

SpartaDeveloper93 commented 1 month ago

@johnsimons , Yeah, it's weird that they will introduce breaking changes with a minor version updates. Thanks for investigating, it's not a big deal for us yet so we will keep our MongoDB library version to 2.27 for now.

SpartaDeveloper93 commented 3 weeks ago

@johnsimons, are there any updates?