Skip to content

[.NET 10 servicing] Backport #123295: Skip() past the end followed by Concat() still throws ArgumentOutOfRangeException on 10.0.12 #134736

Open

Description

@chris-fixportal

Summary

Requesting a release/10.0 backport of #123295, which fixed #123284 on main on 2026-01-20. The bug is a regression in a GA LTS release (introduced by #112401 in .NET 10), the fix is a one-line bounds check, and it is still present in the current servicing release. #123284 is locked, so this is filed separately rather than as a comment there.

Still reproduces on .NET 10.0.12

Microsoft.NETCore.App 10.0.12, Windows x64, Release, net10.0 console app (two-file repro attached below):

.NET 10.0.12
array.Skip(2).ToArray()                          -> 0 element(s)
array.Take(2).Concat(array.Skip(2)).ToArray()    -> THREW ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
    at System.Linq.Enumerable.IListSkipTakeIterator`1.Fill(IList`1 source, Span`1 destination, Int32 sourceIndex)
    at System.Linq.Enumerable.IListSkipTakeIterator`1.CopyTo(TSource[] array, Int32 arrayIndex)
    at System.Linq.Enumerable.Concat2Iterator`1.ToArray()
list.Take(2).Concat(list.Skip(2)).ToArray()      -> THREW ArgumentOutOfRangeException (same stack)

Bare Skip(n).ToArray() past the end is fine; the throw is in the CopyTo/Fill path that Concat (and anything else that fills from the iterator) uses.

Branch state

Impact

Hit in March 2026 in a production WinForms application after moving to .NET 10. A number-format helper did parts.Take(2).Select(...).Concat(parts.Skip(2)).ToArray() over the ;-separated sections of a .NET numeric format string; every single-section format ("N2", the common case) threw from ToArray() on a code path that had been stable since .NET Framework. "Take the first N, transform them, append the rest" is ordinary LINQ, and nothing in the exception points at Skip, so it is expensive to diagnose from the call site. The workaround (Skip(Math.Min(n, source.Length))) is not something most codebases will know to reach for, and the fix already exists.

Repro

using System.Runtime.InteropServices;

Console.WriteLine(RuntimeInformation.FrameworkDescription);
string[] one = ["N2"];
try
{
    Console.WriteLine(one.Take(2).Concat(one.Skip(2)).ToArray().Length + " element(s)");
}
catch (Exception e)
{
    Console.WriteLine($"{e.GetType().Name}: {e.Message}");
}
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net10.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
  </PropertyGroup>
</Project>

Expected: 1 element(s). Actual on 10.0.12: ArgumentOutOfRangeException: Specified argument was out of the range of valid values.

Related

Activity

  1. added
    untriaged
    on Sep 27, 2026
  2. dotnet-policy-service commented on Sep 27, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @dotnet/area-system-linq
    See info in area-owners.md if you want to be subscribed.

  3. MihuBot commented on Sep 27, 2026

    @MihuBot

    I'm a bot. Here is a possible related and/or duplicate issue (I may be wrong):

  4. chris-fixportal commented on Sep 27, 2026

    @chris-fixportal
    Author

    Related, but this isn't a duplicate. dotnet/sdk#52515 is the original report of this bug. It was filed in the SDK repo, closed there, and re-filed here as #123284. #123295 fixed it on main.

    This issue asks for #123295 to be backported to .NET 10 servicing: 10.0.12 still throws, and I can't find a release/10.0 backport PR.

  5. jeremy-morren commented on Oct 30, 2026

    @jeremy-morren

    Still present on 10.0.14.

  6. added 2 commits that reference this issue on Oct 30, 2026
    7968baf
    030dd9c
  7. jeremy-morren commented on Nov 2, 2026

    @jeremy-morren

    Submitted backport pr #123295 on net10 branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-System.Linquntriaged

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions