[CSHARP-1932] Issue with nullable parameter Created: 06/Mar/17  Updated: 01/May/17  Resolved: 06/Mar/17

Status: Closed
Project: C# Driver
Component/s: Linq
Affects Version/s: 2.4.2
Fix Version/s: 2.4.3

Type: Bug Priority: Critical - P2
Reporter: Rob Offer Assignee: Robert Stam
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: Text File Program.cs    
Issue Links:
Duplicate
duplicates CSHARP-1919 Filter builder Where method with null... Closed

 Description   

We are experiencing a null reference exception when attempting to build a filter using a nullable parameter, even though the value is not null.

I have attached a sample file to illustrate the error, if you attempt to use a nullable enumeration as a Type in a LINQ filter you get a null reference exception. I'm aware the type on the serialised class (User) is not nullable, but the nullable parameter is used to distinguish whether a filter is needed or not.

We have isolated this down to the upgrade between 2.4.1 and 2.4.2.



 Comments   
Comment by Robert Stam [ 06/Mar/17 ]

I can reproduce this. It is essentially the same issue as CSHARP-1919 and has been fixed for 2.4.3.

A work around is to use .Value to convert the nullable value to a non-nullable value:

if (userType != null)
    filter = Builders<User>.Filter.Where(u => u.UserType == userType.Value);

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