2017-04-18 07:52:04 +08:00
|
|
|
## List<T>.ForEach can throw exception when modifying list item
|
2017-04-06 04:52:19 +08:00
|
|
|
|
|
|
|
### Scope
|
|
|
|
Edge
|
|
|
|
|
|
|
|
### Version Introduced
|
|
|
|
4.5
|
|
|
|
|
|
|
|
### Source Analyzer Status
|
|
|
|
Available
|
|
|
|
|
|
|
|
### Change Description
|
2017-04-21 02:19:05 +08:00
|
|
|
|
2018-03-01 08:06:28 +08:00
|
|
|
Beginning in .NET Framework 4.5, a
|
2017-04-21 02:19:05 +08:00
|
|
|
<xref:System.Collections.Generic.List`1.ForEach(System.Action{`0})>
|
|
|
|
enumerator will throw an
|
|
|
|
<xref:System.InvalidOperationException?displayProperty=name> exception if an
|
|
|
|
element in the calling collection is modified. Previously, this would not throw
|
|
|
|
an exception but could lead to race conditions.
|
2017-04-06 04:52:19 +08:00
|
|
|
|
|
|
|
- [x] Quirked
|
|
|
|
- [ ] Build-time break
|
|
|
|
|
|
|
|
### Recommended Action
|
2017-04-21 02:19:05 +08:00
|
|
|
|
|
|
|
Ideally, code should be fixed to not modify lists while enumerating their
|
|
|
|
elements because that is never a safe operation. To revert to the previous
|
2018-03-01 08:06:28 +08:00
|
|
|
behavior, though, an app may target .NET Framework 4.0.
|
2017-04-06 04:52:19 +08:00
|
|
|
|
|
|
|
### Affected APIs
|
|
|
|
* ``M:System.Collections.Generic.List`1.ForEach(System.Action{`0})``
|
|
|
|
|
|
|
|
### Category
|
|
|
|
Core
|
|
|
|
|
2017-04-18 07:52:04 +08:00
|
|
|
<!-- breaking change id: 5 -->
|