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

Using the same anonymous type twice in a LINQ query throws an exception

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • 3.0.0
    • Affects Version/s: 2.28.0
    • Component/s: LINQ3
    • None
    • Fully Compatible
    • Dotnet Drivers
    • 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?

      Given the following class:

      private class C
      {
          public int Id { get; set; }
          public int X { get; set; }
      } 

      The following LINQ query:

      var results = collection.AsQueryable()
          .Select(x => new { X = x.X })
          .Select(x => new { X = x.X })
          .Select(x => x.X)
          .ToList();

      throws an exception:

      System.InvalidOperationException : More than one possible serializer found for <>f__AnonymousType96`1[System.Int32] in x. 

       

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

              Created:
              Updated:
              Resolved: