[CSHARP-1929] Using array in Expression Filter throws an exception Created: 01/Mar/17  Updated: 07/Mar/17  Resolved: 07/Mar/17

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

Type: Bug Priority: Major - P3
Reporter: Sif-eydine Ounas [X] Assignee: Robert Stam
Resolution: Done Votes: 0
Labels: Bug
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Local environment (Developer Machine)


Issue Links:
Duplicate
duplicates CSHARP-1777 Regression 2.3 driver- Nullible List ... Closed

 Description   

I am currently trying to update our MongoDB references to the latest (2.4.2) to allow our DBA team to upgrade our environments to the latest Mongo 3.4.

Updating the references using Nugget packages has shown a breaking changes affecting our production code and stopping us from a smooth upgrade.

the issue: when using a nullable type array in the Expression (Func) filter - the mongoC# Driver throws an exception:

{"Unable to cast object of type 'MongoDB.Bson.Serialization.Serializers.ArraySerializer`1[System.Nullable`1[System.Guid]]' to type 'MongoDB.Bson.Serialization.IBsonSerializer`1[System.Guid]'."}

I have added a small app on my github that replicate the issue if that can be of any help.

I am not sure if this was the right channel to log the issue and I want to apoloy if this was not the case.

The github address for the relevant repository: https://github.com/Sifou13/MongoNullableArrayFilterIssue



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

This appears to be a duplicate of CSHARP-1777, which is fixed in 2.4.3.

Comment by Sif-eydine Ounas [X] [ 01/Mar/17 ]

If interested parties in the community don't have the tools to run the app, the bug happens in the second statement below:

Guid?[] myLookupArray = new Guid?[]

{ Value1};

List<MyObject> retrievedObjects = Find<MyObject>(x => myLookupArray.Contains(x.myValue)).Result;

and a workaround for now is to change the two lines as follow:

Guid[] myLookupArray = new Guid[] { Value1}

;(removed the ? for nullable)

List<MyObject> retrievedObjects = Find<MyObject>(x => x.myValue.HasValue && myLookupArray.Contains(x.myValue .Value )).Result;

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