You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Incorrect loop bound in SizeOptIListSelectIterator.ToList #137126
SizeOptIListSelectIterator<TSource, TResult>.ToList() checks the destination list’s Count immediately after constructing it with a capacity. Since Count is zero, the loop never executes and the override returns an empty list for a nonempty source.
Admittedly, this path is non-public and functionally dead, but it hides a ticking time bomb, so would be nice to fix for good hygiene (or remove altogether)
Reproduction Steps
With true
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Reflection;IEnumerable<int>query=new[]{1,2,3}.Select(x =>x*10);MethodInfomethod=query.GetType().GetMethod("ToList",BindingFlags.Public|BindingFlags.Instance|BindingFlags.DeclaredOnly)??thrownewInvalidOperationException("ToList override not found");List<int>result=(List<int>)(method.Invoke(query,null)??thrownewInvalidOperationException("ToList returned null"));Console.WriteLine(query.GetType().Name);Console.WriteLine($"Reflection: [{string.Join(", ",result)}]");Console.WriteLine($"Public API: [{string.Join(", ",query.ToList())}]");
Expected behavior
printing [10, 20, 30], matching enumeration of the query
Actual behavior
prints []
Regression?
The erroneous loop was included when this iterator was introduced in #118156
Known Workarounds
No workaround is needed
Configuration
Windows 10, x64
Reproduced on .NET 10, 11 rc3 and main
Activity
dotnet-policy-service commentedon Nov 7, 2026
Tagging subscribers to this area: @dotnet/area-system-collections
See info in area-owners.md if you want to be subscribed.