[CSHARP-1083] Null reference when serialize logical condition with null Created: 10/Oct/14  Updated: 22/Dec/16  Resolved: 22/Dec/16

Status: Closed
Project: C# Driver
Component/s: Linq, Serialization
Affects Version/s: 1.9.2
Fix Version/s: 2.4.1

Type: Bug Priority: Major - P3
Reporter: Anatoliy Stegniy Assignee: Robert Stam
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Windows 8.1, ASP NET MVC


Issue Links:
Related
is related to CSHARP-1867 Non-nullable members cannot be compar... Closed

 Description   

Appears "Object reference not set to an instance of an object.
   at MongoDB.Bson.Serialization.Serializers.Int32Serializer.Serialize(BsonWriter bsonWriter, Type nominalType, Object value, IBsonSerializationOptions options)
   at MongoDB.Bson.Serialization.BsonSerializationInfo.SerializeValue(Object value)
   at MongoDB.Driver.Linq.PredicateTranslator.BuildComparisonQuery(Expression variableExpression, ExpressionType operatorType, ConstantExpression constantExpression)
   at MongoDB.Driver.Linq.PredicateTranslator.BuildQuery(Expression expression)
   at MongoDB.Driver.Linq.PredicateTranslator.BuildQuery(Expression expression)
   at MongoDB.Driver.Linq.PredicateTranslator.BuildOrElseQuery(BinaryExpression binaryExpression)
   at MongoDB.Driver.Linq.PredicateTranslator.BuildQuery(Expression expression)
   at MongoDB.Driver.Linq.PredicateTranslator.BuildOrElseQuery(BinaryExpression binaryExpression)
   at MongoDB.Driver.Linq.PredicateTranslator.BuildQuery(Expression expression)
   at MongoDB.Driver.Linq.PredicateTranslator.BuildOrElseQuery(BinaryExpression binaryExpression)
   at MongoDB.Driver.Linq.PredicateTranslator.BuildQuery(Expression expression)
   at MongoDB.Driver.Linq.PredicateTranslator.BuildQuery(Expression expression)
   at MongoDB.Driver.Linq.PredicateTranslator.BuildAnyQuery(MethodCallExpression methodCallExpression)
   at MongoDB.Driver.Linq.PredicateTranslator.BuildMethodCallQuery(MethodCallExpression methodCallExpression)
   at MongoDB.Driver.Linq.PredicateTranslator.BuildQuery(Expression expression)
   at MongoDB.Driver.Linq.SelectQuery.Execute()
   at MongoDB.Driver.Linq.MongoQueryable`1.GetEnumerator()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)"

when try to serialalize following query:

var result = _users.Where(u =>
                        u.Profile.AttendedSchools.Any(y =>
                            x.Institution.Id == y.Institution.Id // same school
                            // very long expression for all kinds of year intersection
                            && (
                                (!x.ToPresent && !y.ToPresent && x.FromYear <= y.ToYear && y.FromYear <= x.ToYear) // to present is not set
                                || (x.ToPresent && !y.ToPresent && x.FromYear <= y.ToYear) // first guy is in school now
                                || (!x.ToPresent && y.ToPresent && y.FromYear <= x.ToYear) // second guy is in school now
                                || (x.ToPresent && y.ToPresent) // both is in school now
                            )

where x - object in memory.

Core problem is x.ToYear - it is Nullable<int>, and if it null, exception occurs. Such comparsion is OK for C# code due to http://msdn.microsoft.com/en-us/library/2cf62fcy.aspx



 Comments   
Comment by Robert Stam [ 22/Dec/16 ]

This is related to CSHARP-1867, whose fix also includes supporting null for the nullable constant.

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