[CSHARP-4413] Equality operator of MongoClientSettings is bugged Created: 15/Nov/22  Updated: 28/Oct/23  Resolved: 28/Nov/22

Status: Closed
Project: C# Driver
Component/s: None
Affects Version/s: None
Fix Version/s: 2.19.0

Type: Bug Priority: Unknown
Reporter: Arik Shapiro Assignee: Boris Dogadov
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

Summary

The bug is very obvious, the equality does not work because you forgot to implement an equality operator for the WriteConcern class and you are using the equality operator inside the Equals method of the MongoClientSettings.
therefore it uses the default equality (by reference) and fails.

You might be fooled to think that the equality by reference will still work because you have declared all your WriteConcern types static and use only those.
but in MongoUrl.GetWriteConcern function

you are creating a new instance of WriteConcern out side of the "if".

Please provide the version of the driver. If applicable, please provide the MongoDB server version and topology (standalone, replica set, or sharded cluster).

 

version 2.18.0

 

How to Reproduce

Steps to reproduce. If possible, please include a Short, Self Contained, Correct (Compilable), Example.

 

```

var settings1 = MongoClientSettings.FromConnectionString("mongodb+srv://arik:arik123@test.abcd.mongodb.net/?w=majority"); var settings2 = MongoClientSettings.FromConnectionString("mongodb+srv://arik:arik123@test.abcd.mongodb.net/?w=majority"); Console.WriteLine(settings1 == settings2);

```

Result is false.

 

Additional Background

Please provide any additional background information that may be helpful in diagnosing the bug.



 Comments   
Comment by Githook User [ 28/Nov/22 ]

Author:

{'name': 'BorisDog', 'email': 'BorisDog@users.noreply.github.com', 'username': 'BorisDog'}

Message: CSHARP-4413: Equality operator of MongoClientSettings is bugged (#976)
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/3fd05384a272ee94153fc8136a80656f4e87fd4b

Comment by Dmitry Lukyanov (Inactive) [ 15/Nov/22 ]

Hey arik.shapiro@audiocodes.com, thanks for your report, you're right, we will fix it in one of upcoming releases

Generated at Wed Feb 07 21:48:09 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.