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
AsyncEnumerable.ThenBy with async key selector throws NullReferenceException: secondary keys not awaited #135343
When the ThenBy key selector completes asynchronously, sorting starts before the secondary keys are computed. If the primary keys tie, Compare then reads a null _keys array.
System.InvalidOperationException: Failed to compare two elements in the array.
---> System.NullReferenceException: Object reference not set to an instance of an object.
at System.Linq.AsyncEnumerable.EnumerableSorter`2.Compare(Int32 index1, Int32 index2)
Suggested fix
if(_nextis not null){await_next.ComputeKeysAsync(elements,count,cancellationToken);}
Configuration
.NET 10.0.5, Linux x64 (bug still present on main)
Reproduced on .NET 10.0.12 and .NET 11.0.0-rc.1.26425.128 on Windows x64. ThenByDescending and third-level asynchronous ordering are also affected. A faulted secondary selector can additionally be silently ignored when primary keys differ.
This should remain open as a bug, with regression coverage for selectors that actually suspend and for exception propagation. A tested workaround is to compute the asynchronous keys in Select, then apply OrderBy/ThenBy with synchronous selectors.
Activity
dotnet-policy-service commentedon Oct 7, 2026
Tagging subscribers to this area: @dotnet/area-system-linq
See info in area-owners.md if you want to be subscribed.
eiriktsarpalis commentedon Oct 7, 2026
Reproduced on .NET 10.0.12 and .NET 11.0.0-rc.1.26425.128 on Windows x64.
ThenByDescendingand third-level asynchronous ordering are also affected. A faulted secondary selector can additionally be silently ignored when primary keys differ.This should remain open as a bug, with regression coverage for selectors that actually suspend and for exception propagation. A tested workaround is to compute the asynchronous keys in
Select, then applyOrderBy/ThenBywith synchronous selectors.Await chained key computation in AsyncEnumerable ordering (#135356)