Chadit
Chadit

Reputation: 965

Mongo FindAsync Nullable object must have a value

With C# and Mongo I am trying to do the following

using (var cursor = await MongoCollection.FindAsync(query, findOptions)){
    return await cursor.ToListAsync();
}

it started to throw the error "Nullable object must have a value"

To troubleshoot inside the using statement I converted to this

while (await cursor.MoveNextAsync())

it appears to randomly on the MoveNextAsync() to throw the exception

If I convert to the non-async Find, I seem to get all my objects back correctly.

Digging more into this, I seem to be getting this error if the FindOption has limit set. Sort and Skip seems to work just fine.

Upvotes: 0

Views: 280

Answers (1)

James Woodall
James Woodall

Reputation: 735

I have just received this error.

Upgrading in NuGet to the 2.2.1 C# driver fixed it for me.

https://www.nuget.org/packages/MongoDB.Driver/2.2.1

Upvotes: 1

Related Questions