[CSHARP-4566] Matching on char? throws an ExpressionNotSupportedException Created: 13/Mar/23  Updated: 08/Jan/24

Status: In Progress
Project: C# Driver
Component/s: LINQ3
Affects Version/s: 2.19.0
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: David Golub Assignee: Robert Stam
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
is duplicated by CSHARP-4596 LINQ error in v2.19.1 Closed
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

Please provide a clear and concise description of the bug.
Attempting to query on a field of type char? causes the driver to crash.

Please provide the version of the driver. If applicable, please provide the MongoDB server version and topology (standalone, replica set, or sharded cluster).

This is a regression in version 2.19. The same code runs fine without any problem in version 2.18.

How to Reproduce

Steps to reproduce. If possible, please include a Short, Self Contained, Correct (Compilable), Example.

using MongoDB.Driver;
 
MongoClient client = new MongoClient("mongodb://localhost:27017");
IMongoDatabase db = client.GetDatabase("test");
IMongoCollection<TestObject> coll = db.GetCollection<TestObject>("foo");
coll.Find(x => x.Prop == 'a').ToList();
 
public class TestObject
{
    public char? Prop { get; set; }
}

Additional Background

Please provide any additional background information that may be helpful in diagnosing the bug.



 Comments   
Comment by Wassim Khalil [ 08/Jan/24 ]

Hi, can we please get an update on this? We've been stuck on v2.19 for months now and we'd really like to make use of some of the new features.

Comment by Robert Stam [ 06/Oct/23 ]

Reopening because some remaining issues were discovered.

Comment by Githook User [ 06/Oct/23 ]

Author:

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

Message: Revert "CSHARP-4566: Support widening numeric and nullable-numeric conversions."

This reverts commit e9d6231802f165952731bb1aeb7b531b8edaeb26.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/ca09e64a91941c241b36bb85fcd5a9e9be8c2c5b

Comment by Githook User [ 06/Oct/23 ]

Author:

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

Message: CSHARP-4566: Support widening numeric and nullable-numeric conversions.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/e9d6231802f165952731bb1aeb7b531b8edaeb26

Comment by Shiya Kohn [ 24/Aug/23 ]

Adding our team as dependent on a fix for this, I am quite confident that we have a comparison like this somewhere, seems to be a problem for any binary expression where right side converts to left but not the inverse.

Comment by Robert Stam [ 17/Aug/23 ]

Thanks for checking in. We had taken an initial look at this and made some initial progress but ended up prioritizing other fixes before this one. I will take another look.

Comment by David Golub [ 15/Aug/23 ]

Just wondering what the status of this ticket is. It looks like it hasn't been touched in a couple of months, despite being a regression.

Comment by Bar Arnon [ 30/May/23 ]

I have a similar case on 2.19.2 with no relation to int. It happens when comparing a long? to a double:

Expression not supported: Convert(hamster.Weight, Nullable`1) because conversion to System.Nullable`1[System.Double] is not supported

Comment by James Kovacs [ 13/Mar/23 ]

When writing tests, check char and other types smaller than int32 plus their nullable variants.

Comment by Robert Stam [ 13/Mar/23 ]

Thanks for reporting this. I am able to reproduce this. The exception thrown is:

MongoDB.Driver.Linq.ExpressionNotSupportedException : Expression not supported: Convert(x.Prop, Nullable`1) because conversion to System.Nullable`1[System.Int32] is not supported.
 

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