Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-779

IBsonSerializationOptions are not utilized in Builders when serializing to arrays.

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 1.8.2
    • Affects Version/s: 1.8.1
    • Component/s: None
    • None

      I have a contact in VoucherCloud who are using the C# driver. Their lead developer just emailed me with a problem he is having. Would you be able to provide any feedback? His problem seems to be as follows, with a code example:

      Hi there Sam,

      The core of the problem seems to be an inconsistency in the way that bsonrepresentation attributes are handled by enumerate types.

      Given a guid array which is maker with a bsonrepresentation of string the update.pullall and the query.eq fail to represent the entries in the array (or enumerable) as strings.

      In addition this occurred for types other than guid and on numerous other queries and updates which accept enumerable entries.

      I suspect that it may be more prolific than these specific examples but they are at least a repeatable representation of the issue:

          [TestFixture]
          public class MongoDriverTests
          {
              public class RepresentationExample
              {
                  [BsonRepresentation(BsonType.String)]
                  public Guid[] MultipleEntry { get; set; }
      
                  [BsonRepresentation(BsonType.String)]
                  public Guid SingleEntry { get; set; }
              }
      
              [Test]
              public void InRepresentationIssue()
              {
                  var guid = Guid.NewGuid();
      
                  var singleUpdate = Query<RepresentationExample>
                      .In(x => x.SingleEntry, new[] { guid });
      
                  Assert.That(singleUpdate.ToJson().Contains(guid.ToString()));
                  Assert.That(!singleUpdate.ToJson().Contains("CSUUID"));
      
                  var multipleUpdate = Query<RepresentationExample>
                      .In(x => x.MultipleEntry, new[] { guid });
      
                  Assert.That(multipleUpdate.ToJson(), Contains.Substring(guid.ToString()));
                  Assert.That(!multipleUpdate.ToJson().Contains("CSUUID"));
              }
      
              [Test]
              public void UpdateRepresentationIssue()
              {
                  var guid = Guid.NewGuid();
      
                  var singleUpdate = Update<RepresentationExample>
                      .Set(x => x.SingleEntry, guid);
      
                  Assert.That(singleUpdate.ToJson().Contains(guid.ToString()));
                  Assert.That(!singleUpdate.ToJson().Contains("CSUUID"));
      
                  var multipleUpdate = Update<RepresentationExample>
                      .PullAll(x => x.MultipleEntry, new[] { guid });
      
                  Assert.That(multipleUpdate.ToJson(), Contains.Substring(guid.ToString()));
                  Assert.That(!multipleUpdate.ToJson().Contains("CSUUID"));
              }
          }
      

      Written with NUnit. Hope it helps.

            Assignee:
            craig.wilson@mongodb.com Craig Wilson
            Reporter:
            sam.weaver Sam Weaver
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: