[CSHARP-2218] BsonBinaryData constructor throws incorrect ArgumentException message Created: 18/Mar/18  Updated: 28/Oct/23  Resolved: 02/Apr/18

Status: Closed
Project: C# Driver
Component/s: BSON
Affects Version/s: 2.5
Fix Version/s: 2.5.1

Type: Bug Priority: Trivial - P5
Reporter: James Hadwen Assignee: Robert Stam
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to CSHARP-2074 Improve how GuidRepresentation is han... Closed
Backwards Compatibility: Fully Compatible

 Description   

Error thrown in the lines:

var message = string.Format(
                        "SubType must be {0}, not {1}, when GuidRepresentation is {2}.",
                        expectedSubType, subType, GuidRepresentation);
throw new ArgumentException(message);

However this.GuidRepresentation has yet to be initialized, parameter should actually be guidRepresentation.



 Comments   
Comment by Githook User [ 02/Apr/18 ]

Author:

{'email': 'robert@robertstam.org', 'name': 'rstam', 'username': 'rstam'}

Message: CSHARP-2218: Fix BsonBinaryData constructor exception messages
Branch: v2.5.x
https://github.com/mongodb/mongo-csharp-driver/commit/1a747516dbafd5240d239bea90fec6d030fd2b44

Comment by Githook User [ 02/Apr/18 ]

Author:

{'email': 'robert@robertstam.org', 'name': 'rstam', 'username': 'rstam'}

Message: CSHARP-2218: Fix BsonBinaryData constructor exception messages
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/f5eb70a3dfd35ddb71c4ff1dd927b8ecf32aff49

Comment by Robert Stam [ 02/Apr/18 ]

An instance of BsonBinaryData has two primary properties:

SubType: A enum indicating what type of binary data this is
Bytes: The bytes themselves

In addition, for the two subtypes that represent UUIDs (UuidLegacy and UuidStandard) there is one additional property:

{{GuidRepresentation}:} An enum indicating how the UUID is represented.

There are strict rules about which combinations of SubType and GuidRepresentation are valid:

1. When SubType is UuidStandard, then GuidRepresentation MUST be Standard
2. When SubType is UuidLegacy, then GuidRepresentation MUST be one of: CSharpLegacy, JavaLegacy, PythonLegacy or Unspecified
3. For all other SubType values GuidRepesentation MUST be Unspecified

These rules are enforced by the BsonBinaryData constructors.

Comment by James Hadwen [ 18/Mar/18 ]

To add, I'm not really certain why this constructor (in my case from BsonBinaryReader.ReadBinaryData() within an implementation of SerializerBase<T>) needs to preempt how I might or might not deconstruct the Guid. i.e. if the Guid is stored as LUUID, should I not be allowed to call BsonBinaryReader.ReadBinaryData().ToGuid(GuidRepresentation.CSharpLegacy) even if BsonDefaults.GuidRepresentation is set to Standard?

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