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

LINQ3 Where with enum filter followed by Select with cast throws System.ArgumentException

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • 2.23.0
    • Affects Version/s: 2.22.0
    • Component/s: LINQ3
    • Labels:
      None
    • Fully Compatible
    • Not Needed
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?

      Summary

      When using the LINQ3 provider, a Where filter on enum property in combination with a Select that has a cast, throws System.ArgumentException.

      Driver version 2.22.0

      Using the Where and Select in isolation works, it is only when used in combination that the exception occurs.

      The following query works with LINQ2 but with LINQ3 throws exception System.ArgumentException Value type of serializer is Status and does not match member type System.Int32. (Parameter 'serializer')

      The 'Status' property is an enum and 'Version' is being cast from long to int. See attachment for full source.

      var resultsOpen = coll.AsQueryable()
          .Where(x => x.Status == Status.Open)
          .Select(x => new ResultDoc { Name = x.Name, Version = (int)x.Version })
          .ToList(); // exception

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            anthony.crook@ivanti.com Anthony Crook
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: