[CSHARP-1034] ArgumentNullException when building Pull command on array element without nested property Created: 13/Aug/14  Updated: 04/Apr/15  Resolved: 04/Apr/15

Status: Closed
Project: C# Driver
Component/s: Linq
Affects Version/s: 1.9.1
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Neleus Assignee: Unassigned
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

Following code fails with ArgumentNullException:

var participants = new[]

{ 123, 456, 789 }

;
var builder = new MongoDB.Driver.Builders.UpdateBuilder<Domain.Match>();
var mongoQuery = builder.Pull(m => m.ParticipantNumbers, query => query.Where(p => participants.Contains(p))); //This line fails with the exception

Stack trace:
System.ArgumentNullException: Value cannot be null.
Parameter name: name
at MongoDB.Driver.Builders.Query.In(String name, IEnumerable`1 values)
at MongoDB.Driver.Linq.PredicateTranslator.BuildMethodCallQuery(MethodCallExpression methodCallExpression)
at MongoDB.Driver.Linq.PredicateTranslator.BuildQuery(Expression expression)
at Test.TestClass.<>c_DisplayClass4.<TestMethod>b_3(QueryBuilder`1 query) in c:\dev\TestClass.cs:line 44
at MongoDB.Driver.Builders.UpdateBuilder`1.Pull[TValue](Expression`1 memberExpression, Func`2 elementQueryBuilderFunction)
. . .

My guesses:
It fails when calling query.Where() with lambda expression having no property access: p => participants.Contains(p). (p is a scalar value and used directly by its value). If I change the lambda to some complex object that has a property then it works: query.Where(complexObject => participants.Contains(complexObject.ParticipantNumber)). It seems that the query translator is able to translate expressions with properties only.



 Comments   
Comment by Craig Wilson [ 04/Apr/15 ]

We have rewritten the builders in 2.0 and will not be fixing this.

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