-
Notifications
You must be signed in to change notification settings - Fork 1.3k
CSHARP-5797: Add C# 14 testing #1834
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this 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 adds C# 14 testing infrastructure to the MongoDB C# driver project to ensure compatibility with the upcoming C# 14 language version. The changes include creating a new Release_CSharp_14 build configuration, updating test code to be compatible with C# 14 syntax changes, and configuring CI/CD pipelines to run tests with C# 14.
- Added new
Release_CSharp_14build configuration with LangVersion 14 for test projects while keeping source projects on C# 12 - Updated test code to address C# 14 breaking changes: escaped
fieldidentifiers, explicit array syntax forstring.Concat, and disambiguatedReverse()calls - Configured CI/CD to run unit tests with C# 14 on .NET 10.0 across all platforms
Reviewed changes
Copilot reviewed 23 out of 23 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/BuildProps/Tests.Build.props | Added Release_CSharp_14 configuration with LangVersion 14 and CSHARP_14 conditional compilation symbol |
| src/Directory.Build.props | Added Release_CSharp_14 configuration for source projects (keeps LangVersion at 12) |
| CSharpDriver.sln | Added Release_CSharp_14 configuration mappings for all projects in the solution |
| evergreen/evergreen.yml | Added unit-tests-net100-v14 task for C# 14 testing on all platforms (Windows, Ubuntu, macOS) |
| evergreen/run-unit-tests.sh | Added CONFIGURATION environment variable support with default to 'Release' |
| evergreen/compile-sources.sh | Added CONFIGURATION environment variable support for build command |
| tests/MongoDB.Bson.Tests/Serialization/ExtensionMembersTests.cs | New test file validating C# 14 extension members feature compatibility with serialization |
| tests/MongoDB.Bson.Tests/IO/*.cs (8 files) | Renamed field variables to @field to avoid conflicts with C# 14's contextual keyword in property accessors |
| tests/MongoDB.Driver.Tests/Linq/Linq3ImplementationWithLinq2Tests/Translators/AggregateProjectTranslatorTests.cs | Cast to IEnumerable before calling Reverse() to disambiguate overload resolution |
| tests/MongoDB.Driver.Encryption.Tests/BasicTests.cs | Changed to Enumerable.Reverse() static method to avoid C# 14 overload ambiguity |
| tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/StringConcatMethodToAggregationExpressionTranslatorTests.cs | Updated string.Concat calls to use explicit array syntax instead of params |
| tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp5071Tests.cs | Updated string.Concat calls to use explicit array syntax in 22 test cases |
| tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp5749Tests.cs | Reformatted long method call lines for better readability |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| "stringconstant+stringproperty+stringconstant" => collection.AsQueryable().Select(x => string.Concat(new[] { "X" + x.B + "Z" })), | ||
| "stringconstant+stringproperty+stringproperty" => collection.AsQueryable().Select(x => string.Concat(new[] { "X" + x.B + x.C })), | ||
| "stringproperty+intconstant+stringproperty" => collection.AsQueryable().Select(x => string.Concat(new[] { x.A + 2 + x.C })), | ||
| "stringproperty+intproperty+stringproperty" => collection.AsQueryable().Select(x => string.Concat(new[] { x.A + x.J + x.C})), |
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space before the closing brace. Should be x.C } instead of x.C} for consistency with the other lines in this switch expression.
| "stringproperty+intproperty+stringproperty" => collection.AsQueryable().Select(x => string.Concat(new[] { x.A + x.J + x.C})), | |
| "stringproperty+intproperty+stringproperty" => collection.AsQueryable().Select(x => string.Concat(new[] { x.A + x.J + x.C })), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
damieng
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one minor optional suggestion.
| var field = _instance.GetType().GetField("_disposed", BindingFlags.NonPublic | BindingFlags.Instance); | ||
| return (bool)field.GetValue(_instance); | ||
| var @field = _instance.GetType().GetField("_disposed", BindingFlags.NonPublic | BindingFlags.Instance); | ||
| return (bool)@field.GetValue(_instance); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A static extension method on Object called GetPrivateValue(string name) would be useful in this test lib and reduce a lot of boilerplate/noise across all these methods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something very much like that exists in the Reflector.cs file in the MongoDB.Bson.TestHelpers project.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
| { | ||
| "intproperty" => collection.AsQueryable().Select(x => string.Concat(x.I)), | ||
| "stringproperty" => collection.AsQueryable().Select(x => string.Concat(x.A)), | ||
| "stringproperty" => collection.AsQueryable().Select(x => string.Concat(new[] { x.A })), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another one to add to the C# 14/.NET 10 gotcha list I suspect.
sanych-sun
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM + minor comments
| } | ||
|
|
||
| static Expression VisitSequenceEqualMethod(MethodCallExpression node, MethodInfo method, ReadOnlyCollection<Expression> arguments) | ||
| static Expression VisitSequenceEqualMethod(MethodCallExpression node, MethodInfo method, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: all parameters on the same line, or each on it's own.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, not sure how this happened.
sanych-sun
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
No description provided.