[CSHARP-4811] Linux /.Net 7 / mongodb.driver.core.2.21.0 - ExpressionNotSupportedException Created: 13/Oct/23  Updated: 27/Oct/23  Resolved: 17/Oct/23

Status: Closed
Project: C# Driver
Component/s: LINQ3
Affects Version/s: 2.21.0
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Michele Lauriola Assignee: Boris Dogadov
Resolution: Works as Designed Votes: 0
Labels: Bug
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates CSHARP-4803 Refactor StringExpressionToRegexFilte... Closed
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   

Mongodb Standalone server

Summary

Hello everyone,

I encountered an error when executing the query illustrated below.

varcollection = _mongoDb.GetCollection<MyCollection>();
var data = collection.AsQueryable().Any(x=>x.Identifier==newGuid("72E32DEE-6D98-427E-8863-263414DACC8D"));
The error is:

Exception has occurred: CLR/MongoDB.Driver.Linq.ExpressionNotSupportedException
Exception thrown: 'MongoDB.Driver.Linq.ExpressionNotSupportedException' in MongoDB.Driver.dll: 'Expression not supported: (x.Identifier == 72e32dee-6d98-427e-8863-263414dacc8d).'
   at MongoDB.Driver.Linq.Linq3Implementation.Translators.ExpressionToFilterTranslators.MethodTranslators.StringExpressionToRegexFilterTranslator.TranslateComparisonExpression(TranslationContext context, Expression expression, Expression leftExpression, AstComparisonFilterOperator comparisonOperator, Expression rightExpression)

 

From my understanding, it seems to be related to System.Linq.Queryable while using the MongoDB.Driver version 2.21 in .NET 7.

Does anyone have insights or solutions regarding this issue?

Your assistance is greatly appreciated. Thank you!

How to Reproduce

varcollection = _mongoDb.GetCollection<MyCollection>();
var data = collection.AsQueryable().Any(x=>x.Identifier==newGuid("72E32DEE-6D98-427E-8863-263414DACC8D"));
 



 Comments   
Comment by Boris Dogadov [ 17/Oct/23 ]

Thanks for confirming michele.lauriola@gmail.com.
We are closing this ticket now.

Comment by Michele Lauriola [ 16/Oct/23 ]

robert@mongodb.com you're correct; it's not a bug.

I overlooked the 'JustMyCode' settings.

Thank you all for your assistance, and I apologize for mistakenly reporting an issue.

Comment by Robert Stam [ 14/Oct/23 ]

This looks like it's the same issue as CSHARP-4803.

The exception you are observing is thrown and caught internally. It's not a bug because after catching the exception the correct actions are taken. Nonetheless we have refactored the code a bit to avoid throwing exceptions when possible.

You are probably only seeing the exception because you asked the debugger to stop whenever any exception is thrown.

Comment by Michele Lauriola [ 14/Oct/23 ]

Thank you, Boris, for your assistance.

I'll attempt to create a working example in Visual Studio Code.

My .NET project is quite extensive, so I'll need to extract and clean up a significant amount of content.

I wanted to add one more observation: in my environment, the error surfaces when I set the 'JustMyCode' option to 'false'. Interestingly, when it's set to 'true', no errors are observed.

In both scenarios, however, the functionality remains intact (i.e., the correct records are retrieved).

Is it possible that the exception I'm witnessing is a managed one, triggered in a deeper layer but handled by an upper layer in the call stack with some sort of fallback?

Thank you again for your help

ps: I'd like to note that I couldn't reproduce the error using .NET Fiddle. Here's the link for reference: https://dotnetfiddle.net/mXGTVe

Comment by Boris Dogadov [ 13/Oct/23 ]

Hi michele.lauriola@gmail.com 

I have failed to reproduce this with 2.21 driver and .NET 7 using the sample code (with both LINQ2 and LINQ3).
Is it possible to provide a .NET project that demonstrates the issue?

Thanks.

Comment by PM Bot [ 13/Oct/23 ]

Hi michele.lauriola@gmail.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:26 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.