-
Type:
Bug
-
Resolution: Unresolved
-
Priority:
Unknown
-
None
-
Affects Version/s: 3.10.0, 3.11.1
-
Component/s: LINQ3
-
None
-
None
-
Dotnet Drivers
-
None
-
None
-
None
-
None
-
None
-
None
After upgrading MongoDB .NET/C# Driver from 3.9.0 to 3.10.0 (still reproducible on 3.11.1), a previously working LINQ projection now throws:
System.InvalidOperationException: When called from 'VisitMemberInit', rewriting a node of type 'System.Linq.Expressions.NewExpression' must return a non-null value of the same type...
Environment
• MongoDB.Driver: 3.11.1 (regression started in 3.10.0)
• .NET: 8.0
• Query executed via LINQ3 provider (Find(...).Project(...).ToList())
Repro shape
The exception is thrown in a Project with new DTO { ... } (MemberInit) when formatting a BsonDateTime to string inside projection:
CreatedOn = u.CreatedOn != null && u.CreatedOn.ToNullableLocalTime() != null ? u.CreatedOn.ToNullableLocalTime().GetValueOrDefault().ToString("yyyy-MM-dd") : string.Empty
The rest of the projection contains standard scalar assignments and works.
Observations
• Started only after upgrading from 3.9.0 to 3.10.0.
• Still fails in 3.11.1.
• Rewriting null-check style (?: vs ??) does not help.
• Removing in-projection string/date formatting avoids the exception (formatting client-side after materialization works).
Expected behavior
The query should translate and execute, or return a clear ExpressionNotSupportedException for unsupported expression patterns.
Actual behavior
Driver throws InvalidOperationException from expression visitor rewrite path (VisitMemberInit/NewExpression invariant violation), which looks like an internal translator bug/regression.
Additional context
Call stack points to the Project(...) in repository method, with failure during LINQ translation before materialization.