Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

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

Aperta Adatta ai principianti
#134,736 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
88/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
csharp
Ambito
backend

Direzione di ricerca

Inizia in src/libraries/System.Linq/src/System/Linq/SkipTake.SpeedOpt.cs su release/10.0 e confronta il metodo interessato con la sua versione del ramo main proveniente da #123295. Esegui il repro net10.0 allegato per confermare il fallimento di Concat().ToArray() e verificare che il backport produca 1 elemento senza eccezioni.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

area-System.Linq untriaged
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
  • main: src/libraries/System.Linq/src/System/Linq/SkipTake.SpeedOpt.cs guards the copy with if (sourceIndex < sourceSpan.Length) (from #123295).
  • release/10.0: the same method still reads sourceSpan.Slice(sourceIndex, destination.Length).CopyTo(destination); unconditionally (line 151 as of 2026-09-27).
  • No [release/10.0] PR references #123284 or #123295.
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
  • Regression: #112401 (Improve Enumerable.Skip and Enumerable.Take performance)
  • Report: #123284
  • Fix on main: #123295
Lingua principale
C#
Stelle
18.3k
Fork
5.6k
Merge medio
2g 18h
PR unite (30g)
617

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di dotnet/runtime

Tutte le issue di dotnet/runtime

Issue simili

Altre issue su C#

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.