Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EnsureCapacity() on List<> increments the version #82455

Closed
mikernet opened this issue Feb 21, 2023 · 3 comments · Fixed by #82500
Closed

EnsureCapacity() on List<> increments the version #82455

mikernet opened this issue Feb 21, 2023 · 3 comments · Fixed by #82500

Comments

@mikernet
Copy link
Contributor

Description

Apparent oversight: Setting Capacity or calling TrimExcess() on List<> does not increment the version but calling EnsureCapacity(int) does.

Reproduction Steps

var x = new List<int>();
var e = x.GetEnumerator();
x.EnsureCapacity(10);
e.MoveNext(); // collection modified exception due to version increment

Expected behavior

Calling EnsureCapacity should not increment the version.

Actual behavior

Calling EnsureCapacity increments the version.

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Feb 21, 2023
@ghost
Copy link

ghost commented Feb 21, 2023

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

Issue Details

Description

Apparent oversight: Setting Capacity or calling TrimExcess() on List<> does not increment the version but calling EnsureCapacity(int) does.

Reproduction Steps

var x = new List<int>();
var e = x.GetEnumerator();
x.EnsureCapacity(10);
e.MoveNext(); // collection modified exception due to version increment

Expected behavior

Calling EnsureCapacity should not increment the version.

Actual behavior

Calling EnsureCapacity increments the version.

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

Author: mikernet
Assignees: -
Labels:

area-System.Collections, untriaged

Milestone: -

@hez2010
Copy link
Contributor

hez2010 commented Feb 21, 2023

See #81523
We may remove the check completely in the future.

@mikernet
Copy link
Contributor Author

Yeah, I mentioned this in that discussion as well but wanted to create an issue to track this specifically in case a decision is made to keep the version checks.

@eiriktsarpalis eiriktsarpalis removed the untriaged New issue has not been triaged by the area owner label Feb 22, 2023
@eiriktsarpalis eiriktsarpalis added this to the Future milestone Feb 22, 2023
@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Feb 22, 2023
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Feb 23, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Mar 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants