-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Description
Description
I flipped a variable and found out that .Skip allows the IEnumerable to be modified during enumeration which caused an infinite loop. Related to a similar issue that was moved in [dotnet/corefx] (#32278).
var example = new List<string>() { "test0","test1" };
var i = 0;
foreach (var item in example.Skip(1))
{
example.Add("test");
i++;
if (i > 1000)
{
Console.WriteLine("Modified IEnumerable through LINQ");
break;
}
}Tested without LINQ, and the exception is thrown that you cannot modify a IEnumerable in progress.
Tried with .OrderBy() and it allowed the code to run but did not add new entries to the end of the IEnumerable and would only run twice, which could be a separate bug.
I have not tried with a LINQ/Lambda only statement as the first time this happened it locked a 24gb Ryzen machine.
Configuration
.Net 3.1 ,Windows 10 x64
Regression?
Previously any modification of the IEnumerable while enumerating caused an exception.
Other information
An optimization caused an issue with a similar bug report for 2.1 dealing with infinite loops and IEnumerable [dotnet/corefx] (#32278). It was decided to roll back that merge request to fix the issue.