[CSHARP-1230] NullReferenceException on Find() operation. Created: 03/Apr/15  Updated: 05/Apr/19  Resolved: 27/Jan/16

Status: Closed
Project: C# Driver
Component/s: BSON
Affects Version/s: 2.0
Fix Version/s: None

Type: Task Priority: Blocker - P1
Reporter: mtred Assignee: Unassigned
Resolution: Done Votes: 0
Labels: driver, query, question
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Windows 7, MS Visual Studio 2013, MongoServer v2.4.6, MongoDriver v2.0


Attachments: File Example Code.rar     Text File stacktrace.txt    

 Description   

I installed mongocsharpdriver v2.0, but on one operation in my project:
...
var query1 = Query.EQ();
var query2 = Query.EQ();
var query3 = Query.In();
var query4 = Query.EQ();
var query5 = Query.EQ();
var query6 = Query.Or(query4, query5);
var queryAll = Query.And(query1, query2, query3, query6);
var result = Collection.FindOne(queryAll);
...

i catched exception:
An exception of type 'System.NullReferenceException' occurred in MongoDB.Bson.dll but was not handled in user code
Additional information: Object reference not set to an instance of an object.

But, if i changed this operation like this:
var result = Collection.Count(queryAll); - worked well.

Also, this operation working properly on driver version 1.8 and version 1.10.
What could it be?



 Comments   
Comment by mtred [ 09/Apr/15 ]

UPDATE: Added example console code with errors. (MongoServer 2.4.6, MongoDriver 2.0)

After removing attribute [BsonSerializer] in the class definition - all working good.
I catch exceptions in my project was only due to attributes like [BsonSerializer].

Thanks for all

Comment by mtred [ 08/Apr/15 ]

My project old. There installed driver version 1.8 and everything works fine. After the transfer to version 2.0 i have many errors - BsonSerializer, Collection.Aggregate, and this error - NullException on Find() operation. I changed methods with BsonSerializer, Collection.Aggregate - i think, worked well, but not understand why catched exception on Find() operation.
I tried to recreate a situation similar to this in simple console application, but in this case everything goes fine, no errors.
Earler, i commented (were good), but am i wrong and deleted this comment.
I thought that the problem in connecting to the database. This is partly true. I fixed the connection settings. But the error remained. Now realized that the problem in the request, namely in the class definition. Trying to find the error.

Comment by Craig Wilson [ 08/Apr/15 ]

Hi mtred,

Thanks for the follow-up. I saw a comment that said you were good (and then was deleted), so I wasn't sure what was going on.

I'm still not completely clear on what is being done to cause this problem. If you could create a simple little console program that causes this exception, it would be immensely helpful in getting it fixed.

Thanks,
Craig

Comment by mtred [ 08/Apr/15 ]

Hi Craig,

I think, I found problem on this issue, but i don't know how to solve it. The fact that the data are subjected to search in Query are not like IENumerable, but ENUM.
If i change my query (Query.EQ("status", "active") for this: Query<UserStatus>.EQ(x=>x.status, "active"), then i catched exception:

"Cannot convert lambda expression to delegate type 'System.Func<Transfer.Common.Status,System.Collections.Generic.IEnumerable<string>>' because some of the return types in the block are not implicitly convertible to the delegate return type ...\Common\StatusAccessor.cs"

Comment by Craig Wilson [ 06/Apr/15 ]

Hi mtred,

Thanks for the report. Given the stack trace, we are going to need a lot more information to reproduce this. Can you provide a breaking test or some code in a console program that causes the issue? Particularly, since this happens when automapping a class, we need to see your class definition(s).

Thanks,
Craig

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