Details
-
Bug
-
Resolution: Done
-
Major - P3
-
1.9.2
-
None
-
Windows 8.1, ASP NET MVC
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
Attachments
Issue Links
- is related to
-
CSHARP-1867 Non-nullable members cannot be compared to nullable values
-
- Closed
-