Enumerable.Count() Does Not Check IList<T>.Count - by Chris Marinos

Status : 

  Fixed<br /><br />
		This item has been fixed in the current or upcoming version of this product.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.


2
0
Sign in
to vote
ID 514122 Comments
Status Closed Workarounds
Type Bug Repros 1
Opened 11/24/2009 3:22:15 PM
Access Restriction Public

Description

In this closed bug, it is stated that Enumerable.Count() should check its input IEnumerable to see if it implements either the generic or non-generic version of ICollection:

https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=454130


It seems like the generic version is not being checked in .Net 4.0 Beta 2. I have an IList<T> implementer that gets enumerated when .Count() is called instead of using the .Count property. A test case is included in the steps to reproduce.
Sign in to post a comment.
Posted by Microsoft on 12/17/2009 at 1:53 PM
Thank you for reporting this issue to us.
Yes we found this is a breaking change starting in Beta2 that you can't no longwe implement just ICollection><T>.
We have now fixed this issue and the fix will be in the final version of Visual Studio 2010.

Thank you for using Visual Studio 2010.

Frances Lam
C# Compiler Test Lead
Posted by Microsoft on 11/28/2009 at 4:10 AM
We were able to reproduce the issue you are seeing. We are escalating this bug to the product unit who works on that specific feature area. The product team will review this issue and make a decision on whether they will fix it or not for the next release.
Posted by Microsoft on 11/27/2009 at 7:51 PM
Thank you for your feedback, We are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Posted by Microsoft on 11/26/2009 at 3:57 AM
Thank you for your feedback, We are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Posted by David A Nelson on 11/24/2009 at 4:34 PM
I stand corrected, the test does indeed fail. It appears that contrary to David Sterling's statement in the referenced bug (#454130), the Count method was changed to only check for ICollection, not ICollection<T>. This is a serious breaking change.
Posted by David A Nelson on 11/24/2009 at 3:48 PM
The test passes in Visual Studio 2010 Beta 2 targeting .NET 4.0. Also, checking the implementation of Enumerable.Count in System.Core in .NET 4.0 Beta 2 confirms that the method does call ICollection.Count if available.