Bug 24775 - List.ForEach does not throw InvalidOperationException when collection was modified
Summary: List.ForEach does not throw InvalidOperationException when collection was mod...
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: mscorlib (show other bugs)
Version: master
Hardware: All All
: --- normal
Target Milestone: Untriaged
Assignee: Marek Safar
URL:
Depends on:
Blocks:
 
Reported: 2014-11-24 11:40 UTC by Andrey Akinshin
Modified: 2014-11-25 04:46 UTC (History)
3 users (show)

See Also:
Tags:
Is this bug a regression?: ---
Last known good build:


Attachments

Description Andrey Akinshin 2014-11-24 11:40:49 UTC
*** Overview ***

List.ForEach don't throw InvalidOperationException when collection was modified (the behaviour was changed in .NET Framework 4.5).

*** Minimal example ***

using System;
using System.Collections.Generic;

[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.5", FrameworkDisplayName = ".NET Framework 4.5")]

public class Program
{
    public static void Main()
    {
        var list = new List<int> { 1, 2 };
        try
        {
            list.ForEach(i =>
            {
                if (i == 1)
                    list.Add(3);
                Console.WriteLine(i);
            });
        }
        catch (Exception e)
        {
            Console.WriteLine(e.GetType().Name);
        }
    }
}

*** Expected Results ***
1
InvalidOperationException

*** Actual Results ***
1
2
3

*** Useful links ***

.NET Framework Blog: .NET Framework 4.5 – Off to a great start (http://blogs.msdn.com/b/dotnet/archive/2012/10/17/net-framework-4-5-off-to-a-great-start.aspx)
.NET Web Development and Tools Blog: All about : All about <httpRuntime targetFramework> (http://blogs.msdn.com/b/webdev/archive/2012/11/19/all-about-httpruntime-targetframework.aspx)

*** Run details ***
$ uname -srvmpio ; lsb_release -d
Linux 3.13.0-32-generic #57-Ubuntu SMP Tue Jul 15 03:51:08 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
Description:    Ubuntu 14.04.1 LTS

$ mono --version
Mono JIT compiler version 3.10.0 (tarball Mon Oct 27 14:33:41 IST 2014)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
        TLS:           __thread
        SIGSEGV:       altstack
        Notifications: epoll
        Architecture:  amd64
        Disabled:      none
        Misc:          softdebug 
        LLVM:          supported, not enabled.
        GC:            sgen

$ mcs Program.cs

$ mono Program.exe
1
2
3
Comment 1 Marek Safar 2014-11-25 04:40:35 UTC
Fixed in master

Note You need to log in before you can comment on or make changes to this bug.