Projection to object with string Id member yields CreateCannotDeserializeFromBsonTypeException

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Done
    • Priority: Minor - P4
    • None
    • Affects Version/s: 2.0
    • Component/s: Serialization
    • None
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      This appears to occur with any projection built with Builders<T>.Projection.

      The model class has an Id member which is a string, but no annotation attributes, for example:

      public class SomeClass { public string Id

      {get;set;} public string Name {get;set;}

      }

      var result = _collection.FindOneAndUpdateAsync(filter, updateDef, new FindOneAndUpdateOptions
      {
      IsUpsert = true,
      Projection = Builders<T>.Projection.Expression(u => new

      { U.Id }

      ),
      ReturnDocument = ReturnDocument.Before
      }).Result;

      The exception is thrown in StringSerializer.DeserializeValue. In this case, the local variable bsonType is ObjectId, and _representation is String.

      Am I correct in thinking a check for this, followed by a call to bsonReader.ReadString(), would be the fix?

      If so, I'd like to take the opportunity to build a Pull Request, but am unsure of the testing/submission guidelines, since the page linked to in the docs either no longer exists or has moved from where GitHub points to. Could you advise please?

            Assignee:
            Craig Wilson
            Reporter:
            Kieren Johnstone
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: