[CSHARP-1198] mongodb-csharp-driver throwing NullReferenceException when using CountAsync Created: 20/Mar/15  Updated: 02/Apr/16  Resolved: 20/Mar/15

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

Type: Bug Priority: Major - P3
Reporter: Jeremy Herman Assignee: Craig Wilson
Resolution: Done Votes: 0
Labels: rc
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

REF: https://groups.google.com/forum/#!topic/mongodb-user/yfbzkozHS64

Hi,

Perhaps I'm not use this method properly but I think I am. Here is my code:

IMongoCollection<TType> c = _database2.GetCollection<TType>("MyDocuments");
var f1 = new FilterDefinitionBuilder<TType>();
var fluent = c.Find(f1.Text(queryFilter.SearchTerm));
var result = fluent.CountAsync();

When CountAsync executes (I normally would attach a .Result, but I wanted to isolate the issue here), it throws the following exception:

Object reference not set to an instance of an object.
at MongoDB.Driver.FindFluent`2.CountAsync(CancellationToken cancellationToken)
at ProfileUnity.Mongo.Db.MongoDatabaseManager.<>c__DisplayClass9`1.<GetAll>b__8() in d:\work\proudotnet\src\ProfileUnity.Mongo.Db\MongoDatabaseManager.cs:line 192

I should mention that when I comment out the CountAsync() and replace it with:

var result = fluent.ToListAsync().Result

My correct results are returned. Any advice?

Thanks



 Comments   
Comment by Craig Wilson [ 02/Apr/15 ]

Yes... I simply failed to mark the fix version correctly. My bad and thanks for the report.

Comment by Jeremy Herman [ 02/Apr/15 ]

@Craig Wilson, I was curious if this made it into today's build? Just wanted to be sure the 'Fix Version' is correct or not, as other cases seem to have it reflected.

Comment by Githook User [ 20/Mar/15 ]

Author:

{u'username': u'craiggwilson', u'name': u'Craig Wilson', u'email': u'craiggwilson@gmail.com'}

Message: CSHARP-1198: fixed null reference bug in FindFluent.CountAsync.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/a5ac07a4ac30e6e3ef5960ccc71c0ec031b7783a

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