diff --git a/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/Dictionary.cs b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/Dictionary.cs index bc3040771f001..47105651dacf2 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/Dictionary.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/Dictionary.cs @@ -267,7 +267,6 @@ public void Clear() _freeCount = 0; Array.Clear(_entries, 0, count); } - _version++; } public bool ContainsKey(TKey key) @@ -476,7 +475,6 @@ private bool TryInsert(TKey key, TValue value, InsertionBehavior behavior) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.key); } - _version++; if (_buckets == null) { Initialize(0); @@ -511,6 +509,7 @@ private bool TryInsert(TKey key, TValue value, InsertionBehavior behavior) if (behavior == InsertionBehavior.OverwriteExisting) { entries[i].value = value; + _version++; return true; } @@ -552,6 +551,7 @@ private bool TryInsert(TKey key, TValue value, InsertionBehavior behavior) if (behavior == InsertionBehavior.OverwriteExisting) { entries[i].value = value; + _version++; return true; } @@ -590,6 +590,7 @@ private bool TryInsert(TKey key, TValue value, InsertionBehavior behavior) if (behavior == InsertionBehavior.OverwriteExisting) { entries[i].value = value; + _version++; return true; } @@ -647,6 +648,7 @@ private bool TryInsert(TKey key, TValue value, InsertionBehavior behavior) entry.value = value; // Value in _buckets is 1-based bucket = index + 1; + _version++; // Value types never rehash if (default(TKey) == null && collisionCount > HashHelpers.HashCollisionThreshold && comparer is NonRandomizedStringEqualityComparer)