Skip to content

CSHARP-5928: LINQ Provider throws misleading exception if expression translation is not supported#1915

Merged
sanych-sun merged 3 commits intomongodb:mainfrom
sanych-sun:csharp5928
Mar 17, 2026
Merged

CSHARP-5928: LINQ Provider throws misleading exception if expression translation is not supported#1915
sanych-sun merged 3 commits intomongodb:mainfrom
sanych-sun:csharp5928

Conversation

@sanych-sun
Copy link
Member

No description provided.

@sanych-sun sanych-sun requested a review from a team as a code owner March 16, 2026 22:33
@sanych-sun sanych-sun requested review from adelinowona, ajcvickers, Copilot and damieng and removed request for ajcvickers March 16, 2026 22:33
@sanych-sun sanych-sun added the bug Fixes issues or unintended behavior. label Mar 16, 2026

public static TranslatedExpression TranslateWithoutUnwrapping(TranslationContext context, Expression expression)
{
if (!context.HasResultSerializer(expression))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not validate it here, because serializer could be missing for different reasons here (it could be either not supported combination of parameters for known-expression, non-translatable expression, or simply not implemented yet expression).

{
if (!context.HasResultSerializer(expression))
{
throw new ExpressionNotSupportedException(expression);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does not really matter what we throws here as we will try fallback to expression language on line 45.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves LINQ3 error reporting so that when an expression can’t be translated, the driver throws an ExpressionNotSupportedException that points at the unsupported expression rather than a misleading “couldn’t determine serializer” message.

Changes:

  • Added an integration test covering the Jira case (CSHARP-5928) and asserting the unsupported sub-expression appears in the exception message.
  • Adjusted filter translation to allow falling back to aggregation-operator translation even when a result serializer can’t be determined up-front.
  • Removed the up-front “must have result serializer” guard from aggregation-expression translation and added a targeted serializer validity check in TranslatedExpression.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp5928Tests.cs Adds regression test asserting the thrown exception message references the unsupported Replace(...) expression.
src/MongoDB.Driver/Linq/Linq3Implementation/Translators/ExpressionToFilterTranslators/ExpressionToFilterTranslator.cs Moves the “has result serializer” check into the try-path so failures can fall back to aggregation translation.
src/MongoDB.Driver/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/ExpressionToAggregationExpressionTranslator.cs Removes the up-front serializer guard to avoid masking real translation failures.
src/MongoDB.Driver/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/TranslatedExpression.cs Validates result serializer isn’t an ignore/unknowable marker before storing it.
src/MongoDB.Driver/Linq/Linq3Implementation/Misc/SerializationHelper.cs Adds EnsureValidResultSerializer helper used by TranslatedExpression.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

sanych-sun and others added 2 commits March 16, 2026 17:51
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@sanych-sun sanych-sun merged commit 7cd8de0 into mongodb:main Mar 17, 2026
38 of 45 checks passed
@sanych-sun sanych-sun deleted the csharp5928 branch March 17, 2026 20:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Fixes issues or unintended behavior.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants