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

Unexpected field in deserialization for projection expression with a positional operator

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Gone away
    • Affects Version/s: 2.10.4
    • Fix Version/s: None
    • Component/s: Linq, Serialization
    • Labels:
      None

      Description

       

      var find = collection.Find(x => x.ArrayField.Any(predicate));
       
      var a = find.Project<TypeOfX>(
              Builders<TypeOfX>.Projection
                  .Include(x => x.ArrayField[-1])
                  .Exclude(x => x.Id)
          )
          .FirstOrDefault() // <-- OK
          ?.ArrayField[0];
       
      var b = find.Project(x => x.ArrayField[-1])
          .FirstOrDefault(); // <-- MongoInternalException: Unexpected field

      Both a and b should be the same, but b throws an exception.
      If FirstOrDefault() is replaced with ToString(), both queries are exactly the same. There is a bug in the projection object deserializer.

        Attachments

          Activity

            People

            Assignee:
            mikalai.mazurenka Mikalai Mazurenka (Inactive)
            Reporter:
            wegylexy@gmail.com TimTIM Wong
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: