[CSHARP-1443] Count() throws InvalidOperationException Created: 15/Oct/15  Updated: 20/Jan/16  Resolved: 16/Oct/15

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

Type: Bug Priority: Minor - P4
Reporter: Ilya Assignee: Craig Wilson
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Window 8 64 bit


Attachments: Text File Program.cs    

 Description   

The attached code throws an InvalidOperationException() Sequence contains no elements.

var items = collection.AsQueryable().Where(o => o.Id.Length>100).ToList();
var count = collection.AsQueryable().Where(o => o.Id.Length>100).Count(); // exception thrown here

The items value is 0. I want see count value is 0, but have exception.



 Comments   
Comment by Githook User [ 16/Oct/15 ]

Author:

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

Message: CSHARP-1443: fix issue with no matching documents causing count or sum results of 0 to throw an exception.
Branch: v2.1.x
https://github.com/mongodb/mongo-csharp-driver/commit/d9ac8c090bf615e3e075deade29d1e97cc44abe1

Comment by Githook User [ 16/Oct/15 ]

Author:

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

Message: CSHARP-1443: fix issue with no matching documents causing count or sum results of 0 to throw an exception.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/f76876919511d3b4ad4e27744b2300e4b6e0e87e

Comment by Ilya [ 15/Oct/15 ]

Sorry, version is 2.1.0-rc1. Thanks for your answer.

Comment by Craig Wilson [ 15/Oct/15 ]

I've changed the affects version to 2.1 because 2.0.1 does not include LINQ.

This does look like it's a bug related to how aggregate returns a count when no documents match the filter. Thanks for reporting.

Craig

Comment by Ilya [ 15/Oct/15 ]

Hello. Added file with sample.

Comment by Craig Wilson [ 15/Oct/15 ]

Hi ilya,

We have a great number of tests that exercise this bit of code. Could you provide a sample console program that causes this to occur?

Thanks,
Craig

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