[CSHARP-4821] LINQ3 Where with enum filter followed by Select with cast throws System.ArgumentException Created: 27/Oct/23  Updated: 01/Nov/23  Resolved: 01/Nov/23

Status: Closed
Project: C# Driver
Component/s: LINQ3
Affects Version/s: 2.22.0
Fix Version/s: 2.23.0

Type: Bug Priority: Unknown
Reporter: Anthony Crook Assignee: Robert Stam
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: Zip Archive MongoDriverIssue.zip    
Backwards Compatibility: Fully Compatible
Documentation Changes: Not Needed
Documentation Changes Summary:

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?


 Description   

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



 Comments   
Comment by Githook User [ 01/Nov/23 ]

Author:

{'name': 'rstam', 'email': 'robert@robertstam.org', 'username': 'rstam'}

Message: CSHARP-4821: LINQ3 Where with enum filter followed by Select with cast throws System.ArgumentException.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/190d37cc9298182efdb6484447984459ac26d5ab

Comment by PM Bot [ 27/Oct/23 ]

Hi anthony.crook@ivanti.com, thank you for reporting this issue! The team will look into it and get back to you soon.

Generated at Wed Feb 07 21:49:28 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.