diff --git a/src/coreclr/System.Private.CoreLib/src/System/Array.CoreCLR.cs b/src/coreclr/System.Private.CoreLib/src/System/Array.CoreCLR.cs index 5538d58e8d969..f59ef17a8c219 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/Array.CoreCLR.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/Array.CoreCLR.cs @@ -394,7 +394,7 @@ internal T get_Item(int index) T[] _this = Unsafe.As(this); if ((uint)index >= (uint)_this.Length) { - ThrowHelper.ThrowArgumentOutOfRange_IndexException(); + ThrowHelper.ThrowArgumentOutOfRange_IndexMustBeLessException(); } return _this[index]; @@ -407,7 +407,7 @@ internal void set_Item(int index, T value) T[] _this = Unsafe.As(this); if ((uint)index >= (uint)_this.Length) { - ThrowHelper.ThrowArgumentOutOfRange_IndexException(); + ThrowHelper.ThrowArgumentOutOfRange_IndexMustBeLessException(); } _this[index] = value; diff --git a/src/coreclr/System.Private.CoreLib/src/System/Collections/EmptyReadOnlyDictionaryInternal.cs b/src/coreclr/System.Private.CoreLib/src/System/Collections/EmptyReadOnlyDictionaryInternal.cs index e63e57a3f4a11..894f68eae4171 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/Collections/EmptyReadOnlyDictionaryInternal.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/Collections/EmptyReadOnlyDictionaryInternal.cs @@ -42,7 +42,7 @@ public void CopyTo(Array array!!, int index) throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_NeedNonNegNum); if (array.Length - index < this.Count) - throw new ArgumentException(SR.ArgumentOutOfRange_Index, nameof(index)); + throw new ArgumentException(SR.ArgumentOutOfRange_IndexMustBeLessOrEqual, nameof(index)); // the actual copy is a NOP } diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Array.CoreRT.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Array.CoreRT.cs index 2c1b89bb9bb70..4ce3f07f0e987 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Array.CoreRT.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Array.CoreRT.cs @@ -1234,7 +1234,7 @@ public T this[int index] } catch (IndexOutOfRangeException) { - ThrowHelper.ThrowArgumentOutOfRange_IndexException(); + ThrowHelper.ThrowArgumentOutOfRange_IndexMustBeLessException(); return default; // unreachable } } @@ -1246,7 +1246,7 @@ public T this[int index] } catch (IndexOutOfRangeException) { - ThrowHelper.ThrowArgumentOutOfRange_IndexException(); + ThrowHelper.ThrowArgumentOutOfRange_IndexMustBeLessException(); } } } diff --git a/src/libraries/Common/src/System/Text/DBCSDecoder.cs b/src/libraries/Common/src/System/Text/DBCSDecoder.cs index 7917f5a8a4d39..430ae57db1740 100644 --- a/src/libraries/Common/src/System/Text/DBCSDecoder.cs +++ b/src/libraries/Common/src/System/Text/DBCSDecoder.cs @@ -131,7 +131,7 @@ public override unsafe int GetChars(byte[] bytes!!, int byteIndex, int byteCount throw new ArgumentOutOfRangeException(nameof(bytes), SR.ArgumentOutOfRange_IndexCountBuffer); if (charIndex < 0 || charIndex > chars.Length) - throw new ArgumentOutOfRangeException(nameof(charIndex), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(charIndex), SR.ArgumentOutOfRange_IndexMustBeLessOrEqual); if (chars.Length == 0) return 0; diff --git a/src/libraries/Common/src/System/Text/OSEncoder.cs b/src/libraries/Common/src/System/Text/OSEncoder.cs index 0ee07ef3e888f..f6c618870ebc6 100644 --- a/src/libraries/Common/src/System/Text/OSEncoder.cs +++ b/src/libraries/Common/src/System/Text/OSEncoder.cs @@ -105,7 +105,7 @@ public override unsafe int GetBytes(char[] chars!!, int charIndex, int charCount throw new ArgumentOutOfRangeException(nameof(chars), SR.ArgumentOutOfRange_IndexCountBuffer); if (byteIndex < 0 || byteIndex > bytes.Length) - throw new ArgumentOutOfRangeException(nameof(byteIndex), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(byteIndex), SR.ArgumentOutOfRange_IndexMustBeLessOrEqual); if (bytes.Length == 0) return 0; diff --git a/src/libraries/Common/src/System/Text/OSEncoding.Windows.cs b/src/libraries/Common/src/System/Text/OSEncoding.Windows.cs index ec4af9d9baac8..ff3f3510c6c5b 100644 --- a/src/libraries/Common/src/System/Text/OSEncoding.Windows.cs +++ b/src/libraries/Common/src/System/Text/OSEncoding.Windows.cs @@ -54,7 +54,7 @@ public override unsafe int GetBytes(string s!!, int charIndex, int charCount, by throw new ArgumentOutOfRangeException(nameof(s), SR.ArgumentOutOfRange_IndexCount); if (byteIndex < 0 || byteIndex > bytes.Length) - throw new ArgumentOutOfRangeException(nameof(byteIndex), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(byteIndex), SR.ArgumentOutOfRange_IndexMustBeLessOrEqual); if (charCount == 0) return 0; @@ -80,7 +80,7 @@ public override unsafe int GetBytes(char[] chars!!, int charIndex, int charCount throw new ArgumentOutOfRangeException(nameof(chars), SR.ArgumentOutOfRange_IndexCountBuffer); if (byteIndex < 0 || byteIndex > bytes.Length) - throw new ArgumentOutOfRangeException(nameof(byteIndex), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(byteIndex), SR.ArgumentOutOfRange_IndexMustBeLessOrEqual); if (charCount == 0) return 0; @@ -123,7 +123,7 @@ public override unsafe int GetChars(byte[] bytes!!, int byteIndex, int byteCount throw new ArgumentOutOfRangeException(nameof(bytes), SR.ArgumentOutOfRange_IndexCountBuffer); if (charIndex < 0 || charIndex > chars.Length) - throw new ArgumentOutOfRangeException(nameof(charIndex), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(charIndex), SR.ArgumentOutOfRange_IndexMustBeLessOrEqual); if (byteCount == 0) return 0; diff --git a/src/libraries/System.Collections.NonGeneric/src/Resources/Strings.resx b/src/libraries/System.Collections.NonGeneric/src/Resources/Strings.resx index d45e75764768c..5269011280418 100644 --- a/src/libraries/System.Collections.NonGeneric/src/Resources/Strings.resx +++ b/src/libraries/System.Collections.NonGeneric/src/Resources/Strings.resx @@ -72,9 +72,12 @@ Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection. - + Index was out of range. Must be non-negative and less than the size of the collection. + + Index was out of range. Must be non-negative and less than or equal to the size of the collection. + Non-negative number required. diff --git a/src/libraries/System.Collections.NonGeneric/src/System/Collections/CollectionBase.cs b/src/libraries/System.Collections.NonGeneric/src/System/Collections/CollectionBase.cs index 37a5bd2768f29..13ae957999cd7 100644 --- a/src/libraries/System.Collections.NonGeneric/src/System/Collections/CollectionBase.cs +++ b/src/libraries/System.Collections.NonGeneric/src/System/Collections/CollectionBase.cs @@ -71,7 +71,7 @@ public void Clear() public void RemoveAt(int index) { if (index < 0 || index >= Count) - throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_IndexMustBeLess); object? temp = InnerList[index]; OnValidate(temp!); OnRemove(index, temp); @@ -117,13 +117,13 @@ void ICollection.CopyTo(Array array, int index) get { if (index < 0 || index >= Count) - throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_IndexMustBeLess); return InnerList[index]; } set { if (index < 0 || index >= Count) - throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_IndexMustBeLess); OnValidate(value!); object? temp = InnerList[index]; OnSet(index, temp, value); @@ -189,7 +189,7 @@ int IList.IndexOf(object? value) void IList.Insert(int index, object? value) { if (index < 0 || index > Count) - throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_IndexMustBeLessOrEqual); OnValidate(value!); OnInsert(index, value); InnerList.Insert(index, value); diff --git a/src/libraries/System.Collections.NonGeneric/src/System/Collections/Queue.cs b/src/libraries/System.Collections.NonGeneric/src/System/Collections/Queue.cs index 617fc139e0400..83ecd6044c813 100644 --- a/src/libraries/System.Collections.NonGeneric/src/System/Collections/Queue.cs +++ b/src/libraries/System.Collections.NonGeneric/src/System/Collections/Queue.cs @@ -131,7 +131,7 @@ public virtual void CopyTo(Array array!!, int index) if (array.Rank != 1) throw new ArgumentException(SR.Arg_RankMultiDimNotSupported, nameof(array)); if (index < 0) - throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_IndexMustBeLess); int arrayLen = array.Length; if (arrayLen - index < _size) diff --git a/src/libraries/System.Collections.NonGeneric/src/System/Collections/SortedList.cs b/src/libraries/System.Collections.NonGeneric/src/System/Collections/SortedList.cs index aee2560164c0c..1af9827fdbd8c 100644 --- a/src/libraries/System.Collections.NonGeneric/src/System/Collections/SortedList.cs +++ b/src/libraries/System.Collections.NonGeneric/src/System/Collections/SortedList.cs @@ -378,7 +378,7 @@ private void EnsureCapacity(int min) public virtual object? GetByIndex(int index) { if (index < 0 || index >= Count) - throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_IndexMustBeLess); return values[index]; } @@ -406,7 +406,7 @@ public virtual IDictionaryEnumerator GetEnumerator() // public virtual object GetKey(int index) { - if (index < 0 || index >= Count) throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index); + if (index < 0 || index >= Count) throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_IndexMustBeLess); return keys[index]; } @@ -514,7 +514,7 @@ private void Insert(int index, object key, object? value) // public virtual void RemoveAt(int index) { - if (index < 0 || index >= Count) throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index); + if (index < 0 || index >= Count) throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_IndexMustBeLess); _size--; if (index < _size) { @@ -542,7 +542,7 @@ public virtual void Remove(object key) // public virtual void SetByIndex(int index, object? value) { - if (index < 0 || index >= Count) throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index); + if (index < 0 || index >= Count) throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_IndexMustBeLess); values[index] = value; version++; } diff --git a/src/libraries/System.Collections/src/Resources/Strings.resx b/src/libraries/System.Collections/src/Resources/Strings.resx index d37809a7ab7ad..38e3d082d1a66 100644 --- a/src/libraries/System.Collections/src/Resources/Strings.resx +++ b/src/libraries/System.Collections/src/Resources/Strings.resx @@ -129,9 +129,12 @@ Must be less than or equal to the size of the collection. - + Index was out of range. Must be non-negative and less than the size of the collection. + + Index was out of range. Must be non-negative and less than or equal to the size of the collection. + The LinkedList node does not belong to current LinkedList. diff --git a/src/libraries/System.Collections/src/System/Collections/BitArray.cs b/src/libraries/System.Collections/src/System/Collections/BitArray.cs index f7d8345155053..6214eead4ce27 100644 --- a/src/libraries/System.Collections/src/System/Collections/BitArray.cs +++ b/src/libraries/System.Collections/src/System/Collections/BitArray.cs @@ -981,7 +981,7 @@ private static int Div4Rem(int number, out int remainder) private static void ThrowArgumentOutOfRangeException(int index) { - throw new ArgumentOutOfRangeException(nameof(index), index, SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(index), index, SR.ArgumentOutOfRange_IndexMustBeLess); } private sealed class BitArrayEnumeratorSimple : IEnumerator, ICloneable diff --git a/src/libraries/System.Collections/src/System/Collections/Generic/PriorityQueue.cs b/src/libraries/System.Collections/src/System/Collections/Generic/PriorityQueue.cs index 7eac1a0b54509..ec88e103c3ca3 100644 --- a/src/libraries/System.Collections/src/System/Collections/Generic/PriorityQueue.cs +++ b/src/libraries/System.Collections/src/System/Collections/Generic/PriorityQueue.cs @@ -814,7 +814,7 @@ void ICollection.CopyTo(Array array!!, int index) if (index < 0 || index > array.Length) { - throw new ArgumentOutOfRangeException(nameof(index), index, SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(index), index, SR.ArgumentOutOfRange_IndexMustBeLessOrEqual); } if (array.Length - index < _queue._size) diff --git a/src/libraries/System.Collections/src/System/Collections/Generic/SortedList.cs b/src/libraries/System.Collections/src/System/Collections/Generic/SortedList.cs index 5037964ae0342..bbf4268a6985c 100644 --- a/src/libraries/System.Collections/src/System/Collections/Generic/SortedList.cs +++ b/src/libraries/System.Collections/src/System/Collections/Generic/SortedList.cs @@ -439,7 +439,7 @@ void ICollection>.CopyTo(KeyValuePair[] { if (arrayIndex < 0 || arrayIndex > array.Length) { - throw new ArgumentOutOfRangeException(nameof(arrayIndex), arrayIndex, SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(arrayIndex), arrayIndex, SR.ArgumentOutOfRange_IndexMustBeLessOrEqual); } if (array.Length - arrayIndex < Count) @@ -468,7 +468,7 @@ void ICollection.CopyTo(Array array!!, int index) if (index < 0 || index > array.Length) { - throw new ArgumentOutOfRangeException(nameof(index), index, SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(index), index, SR.ArgumentOutOfRange_IndexMustBeLessOrEqual); } if (array.Length - index < Count) @@ -522,7 +522,7 @@ private void EnsureCapacity(int min) public TValue GetValueAtIndex(int index) { if (index < 0 || index >= _size) - throw new ArgumentOutOfRangeException(nameof(index), index, SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(index), index, SR.ArgumentOutOfRange_IndexMustBeLess); return values[index]; } @@ -530,7 +530,7 @@ public TValue GetValueAtIndex(int index) public void SetValueAtIndex(int index, TValue value) { if (index < 0 || index >= _size) - throw new ArgumentOutOfRangeException(nameof(index), index, SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(index), index, SR.ArgumentOutOfRange_IndexMustBeLess); values[index] = value; version++; } @@ -559,7 +559,7 @@ IEnumerator IEnumerable.GetEnumerator() public TKey GetKeyAtIndex(int index) { if (index < 0 || index >= _size) - throw new ArgumentOutOfRangeException(nameof(index), index, SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(index), index, SR.ArgumentOutOfRange_IndexMustBeLess); return keys[index]; } @@ -681,7 +681,7 @@ public bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value) public void RemoveAt(int index) { if (index < 0 || index >= _size) - throw new ArgumentOutOfRangeException(nameof(index), index, SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(index), index, SR.ArgumentOutOfRange_IndexMustBeLess); _size--; if (index < _size) { diff --git a/src/libraries/System.Collections/src/System/Collections/Generic/Stack.cs b/src/libraries/System.Collections/src/System/Collections/Generic/Stack.cs index 1855c01248540..7d51ad58ba2cb 100644 --- a/src/libraries/System.Collections/src/System/Collections/Generic/Stack.cs +++ b/src/libraries/System.Collections/src/System/Collections/Generic/Stack.cs @@ -96,7 +96,7 @@ public void CopyTo(T[] array!!, int arrayIndex) { if (arrayIndex < 0 || arrayIndex > array.Length) { - throw new ArgumentOutOfRangeException(nameof(arrayIndex), arrayIndex, SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(arrayIndex), arrayIndex, SR.ArgumentOutOfRange_IndexMustBeLessOrEqual); } if (array.Length - arrayIndex < _size) @@ -127,7 +127,7 @@ void ICollection.CopyTo(Array array!!, int arrayIndex) if (arrayIndex < 0 || arrayIndex > array.Length) { - throw new ArgumentOutOfRangeException(nameof(arrayIndex), arrayIndex, SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(arrayIndex), arrayIndex, SR.ArgumentOutOfRange_IndexMustBeLessOrEqual); } if (array.Length - arrayIndex < _size) diff --git a/src/libraries/System.Console/src/Resources/Strings.resx b/src/libraries/System.Console/src/Resources/Strings.resx index 1a29dc6344157..d6b48e2da57fe 100644 --- a/src/libraries/System.Console/src/Resources/Strings.resx +++ b/src/libraries/System.Console/src/Resources/Strings.resx @@ -224,9 +224,12 @@ Index and count must refer to a location within the string. - + Index was out of range. Must be non-negative and less than the size of the collection. + + Index was out of range. Must be non-negative and less than or equal to the size of the collection. + The output byte buffer is too small to contain the encoded data, encoding '{0}' fallback '{1}'. diff --git a/src/libraries/System.Diagnostics.Process/src/Resources/Strings.resx b/src/libraries/System.Diagnostics.Process/src/Resources/Strings.resx index 84f7006f981b1..e946c5268247e 100644 --- a/src/libraries/System.Diagnostics.Process/src/Resources/Strings.resx +++ b/src/libraries/System.Diagnostics.Process/src/Resources/Strings.resx @@ -275,9 +275,12 @@ Index and count must refer to a location within the string. - + Index was out of range. Must be non-negative and less than the size of the collection. + + Index was out of range. Must be non-negative and less than or equal to the size of the collection. + The output byte buffer is too small to contain the encoded data, encoding '{0}' fallback '{1}'. diff --git a/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx b/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx index 69f0f8d1d4ae2..991ab60cc45cc 100644 --- a/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx +++ b/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx @@ -1699,9 +1699,12 @@ Arrays larger than 2GB are not supported. - + Index was out of range. Must be non-negative and less than the size of the collection. + + Index was out of range. Must be non-negative and less than or equal to the size of the collection. + Index and count must refer to a location within the string. diff --git a/src/libraries/System.Private.CoreLib/src/System/Array.cs b/src/libraries/System.Private.CoreLib/src/System/Array.cs index f564e0c5bec52..cb42dbd6159a7 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Array.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Array.cs @@ -919,7 +919,7 @@ public static void Fill(T[] array, T value, int startIndex, int count) if ((uint)startIndex > (uint)array.Length) { - ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index(); + ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_IndexMustBeLessOrEqual(); } if ((uint)count > (uint)(array.Length - startIndex)) @@ -1015,7 +1015,7 @@ public static int FindIndex(T[] array, int startIndex, int count, Predicate array.Length) { - ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index(); + ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_IndexMustBeLessOrEqual(); } if (count < 0 || startIndex > array.Length - count) @@ -1096,7 +1096,7 @@ public static int FindLastIndex(T[] array, int startIndex, int count, Predica // Special case for 0 length List if (startIndex != -1) { - ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index(); + ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_IndexMustBeLess(); } } else @@ -1104,7 +1104,7 @@ public static int FindLastIndex(T[] array, int startIndex, int count, Predica // Make sure we're not out of range if (startIndex < 0 || startIndex >= array.Length) { - ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index(); + ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_IndexMustBeLess(); } } @@ -1183,7 +1183,7 @@ public static int IndexOf(Array array, object? value, int startIndex, int count) int lb = array.GetLowerBound(0); if (startIndex < lb || startIndex > array.Length + lb) - ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index(); + ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_IndexMustBeLessOrEqual(); if (count < 0 || count > array.Length - startIndex + lb) ThrowHelper.ThrowCountArgumentOutOfRange_ArgumentOutOfRange_Count(); @@ -1316,7 +1316,7 @@ public static int IndexOf(T[] array, T value, int startIndex, int count) if ((uint)startIndex > (uint)array.Length) { - ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index(); + ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_IndexMustBeLessOrEqual(); } if ((uint)count > (uint)(array.Length - startIndex)) @@ -1419,7 +1419,7 @@ public static int LastIndexOf(Array array, object? value, int startIndex, int co } if (startIndex < lb || startIndex >= array.Length + lb) - ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index(); + ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_IndexMustBeLess(); if (count < 0) ThrowHelper.ThrowCountArgumentOutOfRange_ArgumentOutOfRange_Count(); if (count > startIndex - lb + 1) @@ -1558,7 +1558,7 @@ public static int LastIndexOf(T[] array, T value, int startIndex, int count) // if (startIndex != -1 && startIndex != 0) { - ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index(); + ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_IndexMustBeLess(); } // only 0 is a valid value for count if array is empty @@ -1572,7 +1572,7 @@ public static int LastIndexOf(T[] array, T value, int startIndex, int count) // Make sure we're not out of range if ((uint)startIndex >= (uint)array.Length) { - ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index(); + ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_IndexMustBeLess(); } // 2nd have of this also catches when startIndex == MAXINT, so MAXINT - 0 + 1 == -1, which is < 0. diff --git a/src/libraries/System.Private.CoreLib/src/System/ArraySegment.cs b/src/libraries/System.Private.CoreLib/src/System/ArraySegment.cs index 2d6c817b87268..a5431a9209295 100644 --- a/src/libraries/System.Private.CoreLib/src/System/ArraySegment.cs +++ b/src/libraries/System.Private.CoreLib/src/System/ArraySegment.cs @@ -81,7 +81,7 @@ public T this[int index] { if ((uint)index >= (uint)_count) { - ThrowHelper.ThrowArgumentOutOfRange_IndexException(); + ThrowHelper.ThrowArgumentOutOfRange_IndexMustBeLessException(); } return _array![_offset + index]; @@ -90,7 +90,7 @@ public T this[int index] { if ((uint)index >= (uint)_count) { - ThrowHelper.ThrowArgumentOutOfRange_IndexException(); + ThrowHelper.ThrowArgumentOutOfRange_IndexMustBeLessException(); } _array![_offset + index] = value; @@ -139,7 +139,7 @@ public ArraySegment Slice(int index) if ((uint)index > (uint)_count) { - ThrowHelper.ThrowArgumentOutOfRange_IndexException(); + ThrowHelper.ThrowArgumentOutOfRange_IndexMustBeLessOrEqualException(); } return new ArraySegment(_array!, _offset + index, _count - index); @@ -151,7 +151,7 @@ public ArraySegment Slice(int index, int count) if ((uint)index > (uint)_count || (uint)count > (uint)(_count - index)) { - ThrowHelper.ThrowArgumentOutOfRange_IndexException(); + ThrowHelper.ThrowArgumentOutOfRange_IndexMustBeLessOrEqualException(); } return new ArraySegment(_array!, _offset + index, count); @@ -184,7 +184,7 @@ T IList.this[int index] { ThrowInvalidOperationIfDefault(); if (index < 0 || index >= _count) - ThrowHelper.ThrowArgumentOutOfRange_IndexException(); + ThrowHelper.ThrowArgumentOutOfRange_IndexMustBeLessException(); return _array![_offset + index]; } @@ -193,7 +193,7 @@ T IList.this[int index] { ThrowInvalidOperationIfDefault(); if (index < 0 || index >= _count) - ThrowHelper.ThrowArgumentOutOfRange_IndexException(); + ThrowHelper.ThrowArgumentOutOfRange_IndexMustBeLessException(); _array![_offset + index] = value; } @@ -223,7 +223,7 @@ T IReadOnlyList.this[int index] { ThrowInvalidOperationIfDefault(); if (index < 0 || index >= _count) - ThrowHelper.ThrowArgumentOutOfRange_IndexException(); + ThrowHelper.ThrowArgumentOutOfRange_IndexMustBeLessException(); return _array![_offset + index]; } diff --git a/src/libraries/System.Private.CoreLib/src/System/BitConverter.cs b/src/libraries/System.Private.CoreLib/src/System/BitConverter.cs index daedb49aaf659..836d3de69a1d0 100644 --- a/src/libraries/System.Private.CoreLib/src/System/BitConverter.cs +++ b/src/libraries/System.Private.CoreLib/src/System/BitConverter.cs @@ -366,7 +366,7 @@ public static short ToInt16(byte[] value, int startIndex) if (value == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.value); if (unchecked((uint)startIndex) >= unchecked((uint)value.Length)) - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index); + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_IndexMustBeLess); if (startIndex > value.Length - sizeof(short)) ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_ArrayPlusOffTooSmall, ExceptionArgument.value); @@ -404,7 +404,7 @@ public static int ToInt32(byte[] value, int startIndex) if (value == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.value); if (unchecked((uint)startIndex) >= unchecked((uint)value.Length)) - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index); + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_IndexMustBeLess); if (startIndex > value.Length - sizeof(int)) ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_ArrayPlusOffTooSmall, ExceptionArgument.value); @@ -442,7 +442,7 @@ public static long ToInt64(byte[] value, int startIndex) if (value == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.value); if (unchecked((uint)startIndex) >= unchecked((uint)value.Length)) - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index); + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_IndexMustBeLess); if (startIndex > value.Length - sizeof(long)) ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_ArrayPlusOffTooSmall, ExceptionArgument.value); @@ -656,7 +656,7 @@ public static string ToString(byte[] value, int startIndex, int length) if (value == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.value); if (startIndex < 0 || startIndex >= value.Length && startIndex > 0) - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index); + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_IndexMustBeLess); if (length < 0) throw new ArgumentOutOfRangeException(nameof(length), SR.ArgumentOutOfRange_GenericPositive); if (startIndex > value.Length - length) @@ -741,9 +741,9 @@ public static bool ToBoolean(byte[] value, int startIndex) if (value == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.value); if (startIndex < 0) - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index); - if (startIndex > value.Length - 1) - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index); // differs from other overloads, which throw base ArgumentException + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_IndexMustBeLess); + if (startIndex >= value.Length) + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_IndexMustBeLess); // differs from other overloads, which throw base ArgumentException return value[startIndex] != 0; } diff --git a/src/libraries/System.Private.CoreLib/src/System/Char.cs b/src/libraries/System.Private.CoreLib/src/System/Char.cs index bef8526bf066d..30433c4d2b864 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Char.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Char.cs @@ -1022,7 +1022,7 @@ public static int ConvertToUtf32(string s, int index) if (index < 0 || index >= s.Length) { - throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_IndexMustBeLess); } // Check if the character at index is a high surrogate. int temp1 = (int)s[index] - CharUnicodeInfo.HIGH_SURROGATE_START; diff --git a/src/libraries/System.Private.CoreLib/src/System/Collections/ArrayList.cs b/src/libraries/System.Private.CoreLib/src/System/Collections/ArrayList.cs index 3bd61b255e20b..f0cf8b8655b3d 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Collections/ArrayList.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Collections/ArrayList.cs @@ -130,12 +130,12 @@ public virtual object? this[int index] { get { - if (index < 0 || index >= _size) throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index); + if (index < 0 || index >= _size) throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_IndexMustBeLess); return _items[index]; } set { - if (index < 0 || index >= _size) throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index); + if (index < 0 || index >= _size) throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_IndexMustBeLess); _items[index] = value; _version++; } @@ -383,7 +383,7 @@ public virtual int IndexOf(object? value) public virtual int IndexOf(object? value, int startIndex) { if (startIndex > _size) - throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_IndexMustBeLessOrEqual); return Array.IndexOf((Array)_items, value, startIndex, _size - startIndex); } @@ -399,7 +399,7 @@ public virtual int IndexOf(object? value, int startIndex) public virtual int IndexOf(object? value, int startIndex, int count) { if (startIndex > _size) - throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_IndexMustBeLessOrEqual); if (count < 0 || startIndex > _size - count) throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_Count); return Array.IndexOf((Array)_items, value, startIndex, count); } @@ -411,7 +411,7 @@ public virtual int IndexOf(object? value, int startIndex, int count) public virtual void Insert(int index, object? value) { // Note that insertions at the end are legal. - if (index < 0 || index > _size) throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index); + if (index < 0 || index > _size) throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_IndexMustBeLessOrEqual); if (_size == _items.Length) EnsureCapacity(_size + 1); if (index < _size) @@ -430,7 +430,7 @@ public virtual void Insert(int index, object? value) // public virtual void InsertRange(int index, ICollection c!!) { - if (index < 0 || index > _size) throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index); + if (index < 0 || index > _size) throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_IndexMustBeLessOrEqual); int count = c.Count; if (count > 0) @@ -475,7 +475,7 @@ public virtual int LastIndexOf(object? value) public virtual int LastIndexOf(object? value, int startIndex) { if (startIndex >= _size) - throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_IndexMustBeLess); return LastIndexOf(value, startIndex, startIndex + 1); } @@ -531,7 +531,7 @@ public virtual void Remove(object? obj) // public virtual void RemoveAt(int index) { - if (index < 0 || index >= _size) throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index); + if (index < 0 || index >= _size) throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_IndexMustBeLess); _size--; if (index < _size) @@ -612,7 +612,7 @@ public virtual void Reverse(int index, int count) public virtual void SetRange(int index, ICollection c!!) { int count = c.Count; - if (index < 0 || index > _size - count) throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index); + if (index < 0 || index > _size - count) throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_IndexMustBeLessOrEqual); if (count > 0) { @@ -878,7 +878,7 @@ public override int IndexOf(object? value, int startIndex) public override int IndexOf(object? value, int startIndex, int count) { - if (startIndex < 0 || startIndex > Count) throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_Index); + if (startIndex < 0 || startIndex > Count) throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_IndexMustBeLessOrEqual); if (count < 0 || startIndex > Count - count) throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_Count); int endIndex = startIndex + count; @@ -906,7 +906,7 @@ public override void Insert(int index, object? obj) public override void InsertRange(int index, ICollection c!!) { - if (index < 0 || index > Count) throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index); + if (index < 0 || index > Count) throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_IndexMustBeLessOrEqual); if (c.Count > 0) { @@ -944,7 +944,7 @@ public override int LastIndexOf(object? value, int startIndex, int count) if (_list.Count == 0) return -1; - if (startIndex < 0 || startIndex >= _list.Count) throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_Index); + if (startIndex < 0 || startIndex >= _list.Count) throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_IndexMustBeLess); if (count < 0 || count > startIndex + 1) throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_Count); int endIndex = startIndex - count + 1; @@ -1018,7 +1018,7 @@ public override void SetRange(int index, ICollection c!!) { if (index < 0 || index > _list.Count - c.Count) { - throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_IndexMustBeLessOrEqual); } if (c.Count > 0) @@ -2368,7 +2368,7 @@ public override int IndexOf(object? value, int startIndex) if (startIndex < 0) throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_NeedNonNegNum); if (startIndex > _baseSize) - throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_IndexMustBeLessOrEqual); InternalUpdateRange(); int i = _baseList.IndexOf(value, _baseIndex + startIndex, _baseSize - startIndex); @@ -2379,7 +2379,7 @@ public override int IndexOf(object? value, int startIndex) public override int IndexOf(object? value, int startIndex, int count) { if (startIndex < 0 || startIndex > _baseSize) - throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_IndexMustBeLessOrEqual); if (count < 0 || (startIndex > _baseSize - count)) throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_Count); @@ -2392,7 +2392,7 @@ public override int IndexOf(object? value, int startIndex, int count) public override void Insert(int index, object? value) { - if (index < 0 || index > _baseSize) throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index); + if (index < 0 || index > _baseSize) throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_IndexMustBeLessOrEqual); InternalUpdateRange(); _baseList.Insert(_baseIndex + index, value); @@ -2402,7 +2402,7 @@ public override void Insert(int index, object? value) public override void InsertRange(int index, ICollection c) { - if (index < 0 || index > _baseSize) throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index); + if (index < 0 || index > _baseSize) throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_IndexMustBeLessOrEqual); ArgumentNullException.ThrowIfNull(c); InternalUpdateRange(); @@ -2435,7 +2435,7 @@ public override int LastIndexOf(object? value, int startIndex, int count) return -1; if (startIndex >= _baseSize) - throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_IndexMustBeLess); if (startIndex < 0) throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_NeedNonNegNum); @@ -2448,7 +2448,7 @@ public override int LastIndexOf(object? value, int startIndex, int count) public override void RemoveAt(int index) { - if (index < 0 || index >= _baseSize) throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index); + if (index < 0 || index >= _baseSize) throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_IndexMustBeLess); InternalUpdateRange(); _baseList.RemoveAt(_baseIndex + index); @@ -2489,7 +2489,7 @@ public override void Reverse(int index, int count) public override void SetRange(int index, ICollection c) { InternalUpdateRange(); - if (index < 0 || index >= _baseSize) throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index); + if (index < 0 || index >= _baseSize) throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_IndexMustBeLess); _baseList.SetRange(_baseIndex + index, c); if (c.Count > 0) { @@ -2514,13 +2514,13 @@ public override object? this[int index] get { InternalUpdateRange(); - if (index < 0 || index >= _baseSize) throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index); + if (index < 0 || index >= _baseSize) throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_IndexMustBeLess); return _baseList[_baseIndex + index]; } set { InternalUpdateRange(); - if (index < 0 || index >= _baseSize) throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index); + if (index < 0 || index >= _baseSize) throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_IndexMustBeLess); _baseList[_baseIndex + index] = value; InternalUpdateVersion(); } diff --git a/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/List.cs b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/List.cs index cc79cb9ab8e56..0d7642bdc4884 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/List.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/List.cs @@ -147,7 +147,7 @@ public T this[int index] // Following trick can reduce the range check by one if ((uint)index >= (uint)_size) { - ThrowHelper.ThrowArgumentOutOfRange_IndexException(); + ThrowHelper.ThrowArgumentOutOfRange_IndexMustBeLessException(); } return _items[index]; } @@ -156,7 +156,7 @@ public T this[int index] { if ((uint)index >= (uint)_size) { - ThrowHelper.ThrowArgumentOutOfRange_IndexException(); + ThrowHelper.ThrowArgumentOutOfRange_IndexMustBeLessException(); } _items[index] = value; _version++; @@ -483,7 +483,7 @@ public int FindIndex(int startIndex, int count, Predicate match) { if ((uint)startIndex > (uint)_size) { - ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index(); + ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_IndexMustBeLessOrEqual(); } if (count < 0 || startIndex > _size - count) @@ -539,7 +539,7 @@ public int FindLastIndex(int startIndex, int count, Predicate match) // Special case for 0 length List if (startIndex != -1) { - ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index(); + ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_IndexMustBeLess(); } } else @@ -547,7 +547,7 @@ public int FindLastIndex(int startIndex, int count, Predicate match) // Make sure we're not out of range if ((uint)startIndex >= (uint)_size) { - ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index(); + ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_IndexMustBeLess(); } } @@ -659,7 +659,7 @@ int IList.IndexOf(object? item) public int IndexOf(T item, int index) { if (index > _size) - ThrowHelper.ThrowArgumentOutOfRange_IndexException(); + ThrowHelper.ThrowArgumentOutOfRange_IndexMustBeLessOrEqualException(); return Array.IndexOf(_items, item, index, _size - index); } @@ -675,7 +675,7 @@ public int IndexOf(T item, int index) public int IndexOf(T item, int index, int count) { if (index > _size) - ThrowHelper.ThrowArgumentOutOfRange_IndexException(); + ThrowHelper.ThrowArgumentOutOfRange_IndexMustBeLessOrEqualException(); if (count < 0 || index > _size - count) ThrowHelper.ThrowCountArgumentOutOfRange_ArgumentOutOfRange_Count(); @@ -732,7 +732,7 @@ public void InsertRange(int index, IEnumerable collection) if ((uint)index > (uint)_size) { - ThrowHelper.ThrowArgumentOutOfRange_IndexException(); + ThrowHelper.ThrowArgumentOutOfRange_IndexMustBeLessOrEqualException(); } if (collection is ICollection c) @@ -809,7 +809,7 @@ public int LastIndexOf(T item) public int LastIndexOf(T item, int index) { if (index >= _size) - ThrowHelper.ThrowArgumentOutOfRange_IndexException(); + ThrowHelper.ThrowArgumentOutOfRange_IndexMustBeLessException(); return LastIndexOf(item, index, index + 1); } @@ -919,7 +919,7 @@ public void RemoveAt(int index) { if ((uint)index >= (uint)_size) { - ThrowHelper.ThrowArgumentOutOfRange_IndexException(); + ThrowHelper.ThrowArgumentOutOfRange_IndexMustBeLessException(); } _size--; if (index < _size) diff --git a/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/Queue.cs b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/Queue.cs index 96424c17c8922..7743370a587ce 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/Queue.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/Queue.cs @@ -99,7 +99,7 @@ public void CopyTo(T[] array!!, int arrayIndex) { if (arrayIndex < 0 || arrayIndex > array.Length) { - throw new ArgumentOutOfRangeException(nameof(arrayIndex), arrayIndex, SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(arrayIndex), arrayIndex, SR.ArgumentOutOfRange_IndexMustBeLessOrEqual); } if (array.Length - arrayIndex < _size) @@ -134,7 +134,7 @@ void ICollection.CopyTo(Array array!!, int index) int arrayLen = array.Length; if (index < 0 || index > arrayLen) { - throw new ArgumentOutOfRangeException(nameof(index), index, SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(index), index, SR.ArgumentOutOfRange_IndexMustBeLessOrEqual); } if (arrayLen - index < _size) diff --git a/src/libraries/System.Private.CoreLib/src/System/Collections/ListDictionaryInternal.cs b/src/libraries/System.Private.CoreLib/src/System/Collections/ListDictionaryInternal.cs index 9189dd6c820f8..feb3e495bba82 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Collections/ListDictionaryInternal.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Collections/ListDictionaryInternal.cs @@ -150,7 +150,7 @@ public void CopyTo(Array array!!, int index) throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_NeedNonNegNum); if (array.Length - index < this.Count) - throw new ArgumentException(SR.ArgumentOutOfRange_Index, nameof(index)); + throw new ArgumentException(SR.ArgumentOutOfRange_IndexMustBeLessOrEqual, nameof(index)); for (DictionaryNode? node = head; node != null; node = node.next) { @@ -300,7 +300,7 @@ void ICollection.CopyTo(Array array!!, int index) if (index < 0) throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_NeedNonNegNum); if (array.Length - index < list.Count) - throw new ArgumentException(SR.ArgumentOutOfRange_Index, nameof(index)); + throw new ArgumentException(SR.ArgumentOutOfRange_IndexMustBeLessOrEqual, nameof(index)); for (DictionaryNode? node = list.head; node != null; node = node.next) { array.SetValue(isKeys ? node.key : node.value, index); diff --git a/src/libraries/System.Private.CoreLib/src/System/Collections/ObjectModel/Collection.cs b/src/libraries/System.Private.CoreLib/src/System/Collections/ObjectModel/Collection.cs index fcafafed633f6..6155619df496a 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Collections/ObjectModel/Collection.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Collections/ObjectModel/Collection.cs @@ -44,7 +44,7 @@ public T this[int index] if ((uint)index >= (uint)items.Count) { - ThrowHelper.ThrowArgumentOutOfRange_IndexException(); + ThrowHelper.ThrowArgumentOutOfRange_IndexMustBeLessException(); } SetItem(index, value); @@ -101,7 +101,7 @@ public void Insert(int index, T item) if ((uint)index > (uint)items.Count) { - ThrowHelper.ThrowArgumentOutOfRange_IndexException(); + ThrowHelper.ThrowArgumentOutOfRange_IndexMustBeLessOrEqualException(); } InsertItem(index, item); @@ -129,7 +129,7 @@ public void RemoveAt(int index) if ((uint)index >= (uint)items.Count) { - ThrowHelper.ThrowArgumentOutOfRange_IndexException(); + ThrowHelper.ThrowArgumentOutOfRange_IndexMustBeLessException(); } RemoveItem(index); diff --git a/src/libraries/System.Private.CoreLib/src/System/Convert.cs b/src/libraries/System.Private.CoreLib/src/System/Convert.cs index bf101862a870c..8747eb98e9ab1 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Convert.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Convert.cs @@ -2315,7 +2315,7 @@ public static string ToBase64String(byte[] inArray, int offset, int length) public static string ToBase64String(byte[] inArray!!, int offset, int length, Base64FormattingOptions options) { if (length < 0) - throw new ArgumentOutOfRangeException(nameof(length), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(length), SR.ArgumentOutOfRange_IndexMustBeLessOrEqual); if (offset < 0) throw new ArgumentOutOfRangeException(nameof(offset), SR.ArgumentOutOfRange_GenericPositive); if (offset > (inArray.Length - length)) @@ -2360,7 +2360,7 @@ public static int ToBase64CharArray(byte[] inArray, int offsetIn, int length, ch public static unsafe int ToBase64CharArray(byte[] inArray!!, int offsetIn, int length, char[] outArray!!, int offsetOut, Base64FormattingOptions options) { if (length < 0) - throw new ArgumentOutOfRangeException(nameof(length), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(length), SR.ArgumentOutOfRange_IndexMustBeLessOrEqual); if (offsetIn < 0) throw new ArgumentOutOfRangeException(nameof(offsetIn), SR.ArgumentOutOfRange_GenericPositive); if (offsetOut < 0) @@ -2685,7 +2685,7 @@ private static void CopyToTempBufferWithoutWhiteSpace(ReadOnlySpan chars, public static byte[] FromBase64CharArray(char[] inArray!!, int offset, int length) { if (length < 0) - throw new ArgumentOutOfRangeException(nameof(length), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(length), SR.ArgumentOutOfRange_IndexMustBeLessOrEqual); if (offset < 0) throw new ArgumentOutOfRangeException(nameof(offset), SR.ArgumentOutOfRange_GenericPositive); @@ -2877,7 +2877,7 @@ public static string ToHexString(byte[] inArray!!) public static string ToHexString(byte[] inArray!!, int offset, int length) { if (length < 0) - throw new ArgumentOutOfRangeException(nameof(length), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(length), SR.ArgumentOutOfRange_IndexMustBeLessOrEqual); if (offset < 0) throw new ArgumentOutOfRangeException(nameof(offset), SR.ArgumentOutOfRange_GenericPositive); if (offset > (inArray.Length - length)) diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/CompareInfo.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/CompareInfo.cs index b4eb5a06b1986..64f012d6b180b 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CompareInfo.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CompareInfo.cs @@ -857,7 +857,7 @@ public unsafe int IndexOf(string source, char value, int startIndex, int count, if ((uint)startIndex > (uint)source.Length) { - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index); + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_IndexMustBeLessOrEqual); } else { @@ -891,7 +891,7 @@ public unsafe int IndexOf(string source, string value, int startIndex, int count if ((uint)startIndex > (uint)source.Length) { - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index); + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_IndexMustBeLessOrEqual); } else { @@ -1202,7 +1202,7 @@ public int LastIndexOf(string source, char value, int startIndex, int count, Com } else { - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index); + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_IndexMustBeLess); } } @@ -1262,7 +1262,7 @@ public int LastIndexOf(string source, string value, int startIndex, int count, C } else { - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index); + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_IndexMustBeLess); } } diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/IdnMapping.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/IdnMapping.cs index 6b5a7b64c9ed8..03af442f3c1b2 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/IdnMapping.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/IdnMapping.cs @@ -66,7 +66,7 @@ public string GetAscii(string unicode!!, int index, int count) if (index < 0 || count < 0) throw new ArgumentOutOfRangeException((index < 0) ? nameof(index) : nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum); if (index > unicode.Length) - throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_IndexMustBeLessOrEqual); if (index > unicode.Length - count) throw new ArgumentOutOfRangeException(nameof(unicode), SR.ArgumentOutOfRange_IndexCountBuffer); @@ -109,7 +109,7 @@ public string GetUnicode(string ascii!!, int index, int count) if (index < 0 || count < 0) throw new ArgumentOutOfRangeException((index < 0) ? nameof(index) : nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum); if (index > ascii.Length) - throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_IndexMustBeLessOrEqual); if (index > ascii.Length - count) throw new ArgumentOutOfRangeException(nameof(ascii), SR.ArgumentOutOfRange_IndexCountBuffer); diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/Ordinal.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/Ordinal.cs index 133330d4acf19..2b982b0b0ed90 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/Ordinal.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/Ordinal.cs @@ -198,7 +198,7 @@ internal static unsafe int IndexOf(string source, string value, int startIndex, if ((uint)startIndex > (uint)source.Length) { - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index); + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_IndexMustBeLessOrEqual); } else { @@ -349,7 +349,7 @@ internal static unsafe int LastIndexOf(string source, string value, int startInd if ((uint)startIndex > (uint)source.Length) { - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index); + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_IndexMustBeLessOrEqual); } else { diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/StringInfo.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/StringInfo.cs index 365bcb3f25d19..f527d59545f3f 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/StringInfo.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/StringInfo.cs @@ -160,7 +160,7 @@ public static int GetNextTextElementLength(string str, int index) } if ((uint)index > (uint)str.Length) { - ThrowHelper.ThrowArgumentOutOfRange_IndexException(); + ThrowHelper.ThrowArgumentOutOfRange_IndexMustBeLessOrEqualException(); } return GetNextTextElementLength(str.AsSpan(index)); @@ -187,7 +187,7 @@ public static TextElementEnumerator GetTextElementEnumerator(string str, int ind } if ((uint)index > (uint)str.Length) { - ThrowHelper.ThrowArgumentOutOfRange_IndexException(); + ThrowHelper.ThrowArgumentOutOfRange_IndexMustBeLessOrEqualException(); } return new TextElementEnumerator(str, index); diff --git a/src/libraries/System.Private.CoreLib/src/System/Numerics/Vector2.cs b/src/libraries/System.Private.CoreLib/src/System/Numerics/Vector2.cs index 70e4f670105a2..ea98c48eec840 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Numerics/Vector2.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Numerics/Vector2.cs @@ -587,7 +587,7 @@ public readonly void CopyTo(float[] array, int index) if ((index < 0) || (index >= array.Length)) { - ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index(); + ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_IndexMustBeLess(); } if ((array.Length - index) < 2) diff --git a/src/libraries/System.Private.CoreLib/src/System/Numerics/Vector3.cs b/src/libraries/System.Private.CoreLib/src/System/Numerics/Vector3.cs index 0d22d4de33e79..ca4c7377a17b1 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Numerics/Vector3.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Numerics/Vector3.cs @@ -609,7 +609,7 @@ public readonly void CopyTo(float[] array, int index) if ((index < 0) || (index >= array.Length)) { - ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index(); + ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_IndexMustBeLess(); } if ((array.Length - index) < 3) diff --git a/src/libraries/System.Private.CoreLib/src/System/Numerics/Vector4.cs b/src/libraries/System.Private.CoreLib/src/System/Numerics/Vector4.cs index 44c87c52c9b92..b7225e3ebf437 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Numerics/Vector4.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Numerics/Vector4.cs @@ -695,7 +695,7 @@ public readonly void CopyTo(float[] array, int index) if ((index < 0) || (index >= array.Length)) { - ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index(); + ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_IndexMustBeLess(); } if ((array.Length - index) < 4) diff --git a/src/libraries/System.Private.CoreLib/src/System/Numerics/Vector_1.cs b/src/libraries/System.Private.CoreLib/src/System/Numerics/Vector_1.cs index e53004f97e902..296f2218186cd 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Numerics/Vector_1.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Numerics/Vector_1.cs @@ -81,7 +81,7 @@ public unsafe Vector(T[] values, int index) if ((index < 0) || ((values.Length - index) < Count)) { - ThrowHelper.ThrowArgumentOutOfRange_IndexException(); + ThrowHelper.ThrowArgumentOutOfRange_IndexMustBeLessOrEqualException(); } this = Unsafe.ReadUnaligned>(ref Unsafe.As(ref values[index])); @@ -536,7 +536,7 @@ public unsafe void CopyTo(T[] destination, int startIndex) if ((uint)startIndex >= (uint)destination.Length) { - ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index(); + ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_IndexMustBeLess(); } if ((destination.Length - startIndex) < Count) diff --git a/src/libraries/System.Private.CoreLib/src/System/ParseNumbers.cs b/src/libraries/System.Private.CoreLib/src/System/ParseNumbers.cs index df5212dff87c8..70fac44ccfe0c 100644 --- a/src/libraries/System.Private.CoreLib/src/System/ParseNumbers.cs +++ b/src/libraries/System.Private.CoreLib/src/System/ParseNumbers.cs @@ -48,7 +48,7 @@ public static long StringToLong(ReadOnlySpan s, int radix, int flags, ref int length = s.Length; if (i < 0 || i >= length) - throw new ArgumentOutOfRangeException(SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(SR.ArgumentOutOfRange_IndexMustBeLess); // Get rid of the whitespace and then check that we've still got some digits to parse. if (((flags & IsTight) == 0) && ((flags & NoSpace) == 0)) @@ -136,7 +136,7 @@ public static int StringToInt(ReadOnlySpan s, int radix, int flags, ref in int length = s.Length; if (i < 0 || i >= length) - throw new ArgumentOutOfRangeException(SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(SR.ArgumentOutOfRange_IndexMustBeLess); // Get rid of the whitespace and then check that we've still got some digits to parse. if (((flags & IsTight) == 0) && ((flags & NoSpace) == 0)) diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector128.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector128.cs index 05704b791a968..b2e4f02535035 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector128.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector128.cs @@ -652,7 +652,7 @@ public static unsafe void CopyTo(this Vector128 vector, T[] destination, i if ((uint)startIndex >= (uint)destination.Length) { - ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index(); + ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_IndexMustBeLess(); } if ((destination.Length - startIndex) < Vector128.Count) @@ -1120,7 +1120,7 @@ public static Vector128 Create(T[] values, int index) if ((index < 0) || ((values.Length - index) < Vector128.Count)) { - ThrowHelper.ThrowArgumentOutOfRange_IndexException(); + ThrowHelper.ThrowArgumentOutOfRange_IndexMustBeLessOrEqualException(); } return Unsafe.ReadUnaligned>(ref Unsafe.As(ref values[index])); diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector256.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector256.cs index 393fbfc84ed01..be8282602365d 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector256.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector256.cs @@ -599,7 +599,7 @@ public static unsafe void CopyTo(this Vector256 vector, T[] destination, i if ((uint)startIndex >= (uint)destination.Length) { - ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index(); + ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_IndexMustBeLess(); } if ((destination.Length - startIndex) < Vector256.Count) @@ -1134,7 +1134,7 @@ public static Vector256 Create(T[] values, int index) if ((index < 0) || ((values.Length - index) < Vector256.Count)) { - ThrowHelper.ThrowArgumentOutOfRange_IndexException(); + ThrowHelper.ThrowArgumentOutOfRange_IndexMustBeLessOrEqualException(); } return Unsafe.ReadUnaligned>(ref Unsafe.As(ref values[index])); diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector64.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector64.cs index a7bc16aeac687..e3bd933159fdb 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector64.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector64.cs @@ -453,7 +453,7 @@ public static unsafe void CopyTo(this Vector64 vector, T[] destination, in if ((uint)startIndex >= (uint)destination.Length) { - ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index(); + ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_IndexMustBeLess(); } if ((destination.Length - startIndex) < Vector64.Count) @@ -869,7 +869,7 @@ public static Vector64 Create(T[] values, int index) if ((index < 0) || ((values.Length - index) < Vector64.Count)) { - ThrowHelper.ThrowArgumentOutOfRange_IndexException(); + ThrowHelper.ThrowArgumentOutOfRange_IndexMustBeLessOrEqualException(); } return Unsafe.ReadUnaligned>(ref Unsafe.As(ref values[index])); diff --git a/src/libraries/System.Private.CoreLib/src/System/String.Comparison.cs b/src/libraries/System.Private.CoreLib/src/System/String.Comparison.cs index 51444d6077064..8b9aadb0c97c2 100644 --- a/src/libraries/System.Private.CoreLib/src/System/String.Comparison.cs +++ b/src/libraries/System.Private.CoreLib/src/System/String.Comparison.cs @@ -388,13 +388,13 @@ public static int Compare(string? strA, int indexA, string? strB, int indexB, in if (indexA < 0 || indexB < 0) { string paramName = indexA < 0 ? nameof(indexA) : nameof(indexB); - throw new ArgumentOutOfRangeException(paramName, SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(paramName, SR.ArgumentOutOfRange_IndexMustBeLessOrEqual); } if (strA.Length - indexA < 0 || strB.Length - indexB < 0) { string paramName = strA.Length - indexA < 0 ? nameof(indexA) : nameof(indexB); - throw new ArgumentOutOfRangeException(paramName, SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(paramName, SR.ArgumentOutOfRange_IndexMustBeLessOrEqual); } if (length == 0 || (object.ReferenceEquals(strA, strB) && indexA == indexB)) @@ -483,7 +483,7 @@ public static int CompareOrdinal(string? strA, int indexA, string? strB, int ind if (indexA < 0 || indexB < 0) { string paramName = indexA < 0 ? nameof(indexA) : nameof(indexB); - throw new ArgumentOutOfRangeException(paramName, SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(paramName, SR.ArgumentOutOfRange_IndexMustBeLessOrEqual); } int lengthA = Math.Min(length, strA.Length - indexA); @@ -492,7 +492,7 @@ public static int CompareOrdinal(string? strA, int indexA, string? strB, int ind if (lengthA < 0 || lengthB < 0) { string paramName = lengthA < 0 ? nameof(indexA) : nameof(indexB); - throw new ArgumentOutOfRangeException(paramName, SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(paramName, SR.ArgumentOutOfRange_IndexMustBeLessOrEqual); } if (length == 0 || (object.ReferenceEquals(strA, strB) && indexA == indexB)) diff --git a/src/libraries/System.Private.CoreLib/src/System/String.Searching.cs b/src/libraries/System.Private.CoreLib/src/System/String.Searching.cs index 6b2d551471771..150018288ae09 100644 --- a/src/libraries/System.Private.CoreLib/src/System/String.Searching.cs +++ b/src/libraries/System.Private.CoreLib/src/System/String.Searching.cs @@ -71,7 +71,7 @@ public unsafe int IndexOf(char value, int startIndex, int count) { if ((uint)startIndex > (uint)Length) { - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index); + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_IndexMustBeLessOrEqual); } if ((uint)count > (uint)(Length - startIndex)) @@ -111,7 +111,7 @@ public int IndexOfAny(char[] anyOf, int startIndex, int count) if ((uint)startIndex > (uint)Length) { - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index); + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_IndexMustBeLessOrEqual); } if ((uint)count > (uint)(Length - startIndex)) @@ -280,7 +280,7 @@ public unsafe int LastIndexOf(char value, int startIndex, int count) if ((uint)startIndex >= (uint)Length) { - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index); + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_IndexMustBeLess); } if ((uint)count > (uint)startIndex + 1) @@ -328,7 +328,7 @@ public unsafe int LastIndexOfAny(char[] anyOf, int startIndex, int count) if ((uint)startIndex >= (uint)Length) { - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index); + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_IndexMustBeLess); } if ((count < 0) || ((count - 1) > startIndex)) diff --git a/src/libraries/System.Private.CoreLib/src/System/String.cs b/src/libraries/System.Private.CoreLib/src/System/String.cs index 39f346ddde33c..02e1d10ded23b 100644 --- a/src/libraries/System.Private.CoreLib/src/System/String.cs +++ b/src/libraries/System.Private.CoreLib/src/System/String.cs @@ -90,7 +90,7 @@ private static string Ctor(char[] value!!, int startIndex, int length) throw new ArgumentOutOfRangeException(nameof(length), SR.ArgumentOutOfRange_NegativeLength); if (startIndex > value.Length - length) - throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_IndexMustBeLessOrEqual); if (length == 0) return Empty; @@ -390,7 +390,7 @@ public unsafe void CopyTo(int sourceIndex, char[] destination!!, int destination if (count < 0) throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_NegativeCount); if (sourceIndex < 0) - throw new ArgumentOutOfRangeException(nameof(sourceIndex), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(sourceIndex), SR.ArgumentOutOfRange_IndexMustBeLessOrEqual); if (count > Length - sourceIndex) throw new ArgumentOutOfRangeException(nameof(sourceIndex), SR.ArgumentOutOfRange_IndexCount); if (destinationIndex > destination.Length - count || destinationIndex < 0) @@ -455,13 +455,13 @@ public char[] ToCharArray(int startIndex, int length) { // Range check everything. if (startIndex < 0 || startIndex > Length || startIndex > Length - length) - throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_IndexMustBeLessOrEqual); if (length <= 0) { if (length == 0) return Array.Empty(); - throw new ArgumentOutOfRangeException(nameof(length), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(length), SR.ArgumentOutOfRange_NegativeLength); } char[] chars = new char[length]; diff --git a/src/libraries/System.Private.CoreLib/src/System/Text/ASCIIEncoding.cs b/src/libraries/System.Private.CoreLib/src/System/Text/ASCIIEncoding.cs index c0ef4599d9f7d..e39722eb67943 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Text/ASCIIEncoding.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Text/ASCIIEncoding.cs @@ -236,7 +236,7 @@ public override unsafe int GetBytes(string chars, int charIndex, int charCount, if ((uint)byteIndex > bytes!.Length) { - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.byteIndex, ExceptionResource.ArgumentOutOfRange_Index); + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.byteIndex, ExceptionResource.ArgumentOutOfRange_IndexMustBeLessOrEqual); } fixed (char* pChars = chars) @@ -286,7 +286,7 @@ public override unsafe int GetBytes(char[] chars, int charIndex, int charCount, if ((uint)byteIndex > bytes!.Length) { - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.byteIndex, ExceptionResource.ArgumentOutOfRange_Index); + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.byteIndex, ExceptionResource.ArgumentOutOfRange_IndexMustBeLessOrEqual); } fixed (char* pChars = chars) @@ -570,7 +570,7 @@ public override unsafe int GetChars(byte[] bytes, int byteIndex, int byteCount, if ((uint)charIndex > (uint)chars!.Length) { - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.charIndex, ExceptionResource.ArgumentOutOfRange_Index); + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.charIndex, ExceptionResource.ArgumentOutOfRange_IndexMustBeLessOrEqual); } fixed (byte* pBytes = bytes) diff --git a/src/libraries/System.Private.CoreLib/src/System/Text/DecoderNLS.cs b/src/libraries/System.Private.CoreLib/src/System/Text/DecoderNLS.cs index e1bf717d9b6e6..7b51214092c7e 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Text/DecoderNLS.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Text/DecoderNLS.cs @@ -98,7 +98,7 @@ public override unsafe int GetChars(byte[] bytes!!, int byteIndex, int byteCount if (charIndex < 0 || charIndex > chars.Length) throw new ArgumentOutOfRangeException(nameof(charIndex), - SR.ArgumentOutOfRange_Index); + SR.ArgumentOutOfRange_IndexMustBeLessOrEqual); int charCount = chars.Length - charIndex; diff --git a/src/libraries/System.Private.CoreLib/src/System/Text/EncoderNLS.cs b/src/libraries/System.Private.CoreLib/src/System/Text/EncoderNLS.cs index e56ef58bd0a66..94aa34626abd9 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Text/EncoderNLS.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Text/EncoderNLS.cs @@ -89,7 +89,7 @@ public override unsafe int GetBytes(char[] chars!!, int charIndex, int charCount if (byteIndex < 0 || byteIndex > bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteIndex), - SR.ArgumentOutOfRange_Index); + SR.ArgumentOutOfRange_IndexMustBeLessOrEqual); int byteCount = bytes.Length - byteIndex; diff --git a/src/libraries/System.Private.CoreLib/src/System/Text/Latin1Encoding.cs b/src/libraries/System.Private.CoreLib/src/System/Text/Latin1Encoding.cs index 01f6710a9632f..eff9412534681 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Text/Latin1Encoding.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Text/Latin1Encoding.cs @@ -225,7 +225,7 @@ public unsafe override int GetBytes(char[] chars, int charIndex, int charCount, if ((uint)byteIndex > bytes!.Length) { - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.byteIndex, ExceptionResource.ArgumentOutOfRange_Index); + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.byteIndex, ExceptionResource.ArgumentOutOfRange_IndexMustBeLessOrEqual); } fixed (char* pChars = chars) @@ -271,7 +271,7 @@ public override unsafe int GetBytes(string s, int charIndex, int charCount, byte if ((uint)byteIndex > bytes!.Length) { - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.byteIndex, ExceptionResource.ArgumentOutOfRange_Index); + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.byteIndex, ExceptionResource.ArgumentOutOfRange_IndexMustBeLessOrEqual); } fixed (char* pChars = s) @@ -478,7 +478,7 @@ public unsafe override int GetChars(byte[] bytes, int byteIndex, int byteCount, if ((uint)charIndex > (uint)chars.Length) { - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.charIndex, ExceptionResource.ArgumentOutOfRange_Index); + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.charIndex, ExceptionResource.ArgumentOutOfRange_IndexMustBeLessOrEqual); } fixed (byte* pBytes = bytes) diff --git a/src/libraries/System.Private.CoreLib/src/System/Text/Rune.cs b/src/libraries/System.Private.CoreLib/src/System/Text/Rune.cs index b4e226b64d1fb..5461301f4e471 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Text/Rune.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Text/Rune.cs @@ -849,7 +849,7 @@ private static int ReadRuneFromString(string input, int index) if ((uint)index >= (uint)input!.Length) { - ThrowHelper.ThrowArgumentOutOfRange_IndexException(); + ThrowHelper.ThrowArgumentOutOfRange_IndexMustBeLessException(); } // Optimistically assume input is within BMP. diff --git a/src/libraries/System.Private.CoreLib/src/System/Text/StringBuilder.cs b/src/libraries/System.Private.CoreLib/src/System/Text/StringBuilder.cs index 284595b9f55c1..c5f924ad754b4 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Text/StringBuilder.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Text/StringBuilder.cs @@ -355,7 +355,7 @@ public override string ToString() // Check that we will not overrun our boundaries. if ((uint)(chunkLength + chunkOffset) > (uint)result.Length || (uint)chunkLength > (uint)sourceArray.Length) { - throw new ArgumentOutOfRangeException(nameof(chunkLength), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(chunkLength), SR.ArgumentOutOfRange_IndexMustBeLessOrEqual); } Buffer.Memmove( @@ -507,7 +507,7 @@ public char this[int index] { if (indexInBlock >= chunk.m_ChunkLength) { - throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_IndexMustBeLess); } chunk.m_ChunkChars[indexInBlock] = value; return; @@ -515,7 +515,7 @@ public char this[int index] chunk = chunk.m_ChunkPrevious; if (chunk == null) { - throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_IndexMustBeLess); } } } @@ -751,7 +751,7 @@ public StringBuilder Append(char[]? value, int startIndex, int charCount) } if (charCount > value.Length - startIndex) { - throw new ArgumentOutOfRangeException(nameof(charCount), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(charCount), SR.ArgumentOutOfRange_IndexMustBeLessOrEqual); } if (charCount != 0) @@ -786,7 +786,7 @@ public StringBuilder Append(string? value, int startIndex, int count) { if (startIndex < 0) { - throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_IndexMustBeLessOrEqual); } if (count < 0) { @@ -806,7 +806,7 @@ public StringBuilder Append(string? value, int startIndex, int count) { if (startIndex > value.Length - count) { - throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_IndexMustBeLessOrEqual); } Append(ref Unsafe.Add(ref value.GetRawStringData(), startIndex), count); @@ -828,7 +828,7 @@ public StringBuilder Append(StringBuilder? value, int startIndex, int count) { if (startIndex < 0) { - throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_IndexMustBeLessOrEqual); } if (count < 0) @@ -852,7 +852,7 @@ public StringBuilder Append(StringBuilder? value, int startIndex, int count) if (count > value.Length - startIndex) { - throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_IndexMustBeLessOrEqual); } return AppendCore(value, startIndex, count); @@ -922,7 +922,7 @@ public void CopyTo(int sourceIndex, Span destination, int count) if ((uint)sourceIndex > (uint)Length) { - throw new ArgumentOutOfRangeException(nameof(sourceIndex), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(sourceIndex), SR.ArgumentOutOfRange_IndexMustBeLessOrEqual); } if (sourceIndex > Length - count) @@ -977,7 +977,7 @@ private StringBuilder Insert(int index, ReadOnlySpan value, int count) int currentLength = Length; if ((uint)index > (uint)currentLength) { - throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_IndexMustBeLessOrEqual); } if (value.IsEmpty || count == 0) @@ -1025,7 +1025,7 @@ public StringBuilder Remove(int startIndex, int length) if (length > Length - startIndex) { - throw new ArgumentOutOfRangeException(nameof(length), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(length), SR.ArgumentOutOfRange_IndexMustBeLessOrEqual); } if (Length == length && startIndex == 0) @@ -1265,7 +1265,7 @@ public StringBuilder Insert(int index, string? value) { if ((uint)index > (uint)Length) { - throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_IndexMustBeLessOrEqual); } if (value != null) @@ -1292,7 +1292,7 @@ public StringBuilder Insert(int index, char value) { if ((uint)index > (uint)Length) { - throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_IndexMustBeLessOrEqual); } Insert(index, ref value, 1); @@ -1303,7 +1303,7 @@ public StringBuilder Insert(int index, char[]? value) { if ((uint)index > (uint)Length) { - throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_IndexMustBeLessOrEqual); } if (value != null) @@ -1318,7 +1318,7 @@ public StringBuilder Insert(int index, char[]? value, int startIndex, int charCo int currentLength = Length; if ((uint)index > (uint)currentLength) { - throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_IndexMustBeLessOrEqual); } if (value == null) @@ -1342,7 +1342,7 @@ public StringBuilder Insert(int index, char[]? value, int startIndex, int charCo if (startIndex > value.Length - charCount) { - throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_IndexMustBeLessOrEqual); } if (charCount > 0) @@ -1378,7 +1378,7 @@ public StringBuilder Insert(int index, ReadOnlySpan value) { if ((uint)index > (uint)Length) { - throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_IndexMustBeLessOrEqual); } if (value.Length != 0) @@ -1851,11 +1851,11 @@ public StringBuilder Replace(string oldValue, string? newValue, int startIndex, int currentLength = Length; if ((uint)startIndex > (uint)currentLength) { - throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_IndexMustBeLessOrEqual); } if (count < 0 || startIndex > currentLength - count) { - throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_IndexMustBeLessOrEqual); } ArgumentException.ThrowIfNullOrEmpty(oldValue); @@ -1936,12 +1936,12 @@ public StringBuilder Replace(char oldChar, char newChar, int startIndex, int cou int currentLength = Length; if ((uint)startIndex > (uint)currentLength) { - throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_IndexMustBeLessOrEqual); } if (count < 0 || startIndex > currentLength - count) { - throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_IndexMustBeLessOrEqual); } int endIndex = startIndex + count; diff --git a/src/libraries/System.Private.CoreLib/src/System/Text/UTF32Encoding.cs b/src/libraries/System.Private.CoreLib/src/System/Text/UTF32Encoding.cs index f566622ce70ac..0efbc0d0345e9 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Text/UTF32Encoding.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Text/UTF32Encoding.cs @@ -155,7 +155,7 @@ public override unsafe int GetBytes(string s!!, int charIndex, int charCount, throw new ArgumentOutOfRangeException(nameof(s), SR.ArgumentOutOfRange_IndexCount); if (byteIndex < 0 || byteIndex > bytes.Length) - throw new ArgumentOutOfRangeException(nameof(byteIndex), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(byteIndex), SR.ArgumentOutOfRange_IndexMustBeLessOrEqual); int byteCount = bytes.Length - byteIndex; @@ -188,7 +188,7 @@ public override unsafe int GetBytes(char[] chars!!, int charIndex, int charCount throw new ArgumentOutOfRangeException(nameof(chars), SR.ArgumentOutOfRange_IndexCountBuffer); if (byteIndex < 0 || byteIndex > bytes.Length) - throw new ArgumentOutOfRangeException(nameof(byteIndex), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(byteIndex), SR.ArgumentOutOfRange_IndexMustBeLessOrEqual); // If nothing to encode return 0, avoid fixed problem if (charCount == 0) @@ -272,7 +272,7 @@ public override unsafe int GetChars(byte[] bytes!!, int byteIndex, int byteCount throw new ArgumentOutOfRangeException(nameof(bytes), SR.ArgumentOutOfRange_IndexCountBuffer); if (charIndex < 0 || charIndex > chars.Length) - throw new ArgumentOutOfRangeException(nameof(charIndex), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(charIndex), SR.ArgumentOutOfRange_IndexMustBeLessOrEqual); // If no input, return 0 & avoid fixed problem if (byteCount == 0) diff --git a/src/libraries/System.Private.CoreLib/src/System/Text/UTF7Encoding.cs b/src/libraries/System.Private.CoreLib/src/System/Text/UTF7Encoding.cs index 118e1d6f5c600..a879de211205a 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Text/UTF7Encoding.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Text/UTF7Encoding.cs @@ -198,7 +198,7 @@ public override unsafe int GetBytes(string s!!, int charIndex, int charCount, throw new ArgumentOutOfRangeException(nameof(s), SR.ArgumentOutOfRange_IndexCount); if (byteIndex < 0 || byteIndex > bytes.Length) - throw new ArgumentOutOfRangeException(nameof(byteIndex), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(byteIndex), SR.ArgumentOutOfRange_IndexMustBeLessOrEqual); int byteCount = bytes.Length - byteIndex; @@ -231,7 +231,7 @@ public override unsafe int GetBytes(char[] chars!!, int charIndex, int charCount throw new ArgumentOutOfRangeException(nameof(chars), SR.ArgumentOutOfRange_IndexCountBuffer); if (byteIndex < 0 || byteIndex > bytes.Length) - throw new ArgumentOutOfRangeException(nameof(byteIndex), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(byteIndex), SR.ArgumentOutOfRange_IndexMustBeLessOrEqual); // If nothing to encode return 0, avoid fixed problem if (charCount == 0) @@ -315,7 +315,7 @@ public override unsafe int GetChars(byte[] bytes!!, int byteIndex, int byteCount throw new ArgumentOutOfRangeException(nameof(bytes), SR.ArgumentOutOfRange_IndexCountBuffer); if (charIndex < 0 || charIndex > chars.Length) - throw new ArgumentOutOfRangeException(nameof(charIndex), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(charIndex), SR.ArgumentOutOfRange_IndexMustBeLessOrEqual); // If no input, return 0 & avoid fixed problem if (byteCount == 0) diff --git a/src/libraries/System.Private.CoreLib/src/System/Text/UTF8Encoding.cs b/src/libraries/System.Private.CoreLib/src/System/Text/UTF8Encoding.cs index 7a20562189acc..3178c39fcc155 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Text/UTF8Encoding.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Text/UTF8Encoding.cs @@ -284,7 +284,7 @@ public override unsafe int GetBytes(string s, int charIndex, int charCount, if ((uint)byteIndex > bytes.Length) { - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.byteIndex, ExceptionResource.ArgumentOutOfRange_Index); + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.byteIndex, ExceptionResource.ArgumentOutOfRange_IndexMustBeLessOrEqual); } fixed (char* pChars = s) @@ -334,7 +334,7 @@ public override unsafe int GetBytes(char[] chars, int charIndex, int charCount, if ((uint)byteIndex > bytes.Length) { - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.byteIndex, ExceptionResource.ArgumentOutOfRange_Index); + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.byteIndex, ExceptionResource.ArgumentOutOfRange_IndexMustBeLessOrEqual); } fixed (char* pChars = chars) @@ -519,7 +519,7 @@ public override unsafe int GetChars(byte[] bytes, int byteIndex, int byteCount, if ((uint)charIndex > (uint)chars.Length) { - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.charIndex, ExceptionResource.ArgumentOutOfRange_Index); + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.charIndex, ExceptionResource.ArgumentOutOfRange_IndexMustBeLessOrEqual); } fixed (byte* pBytes = bytes) diff --git a/src/libraries/System.Private.CoreLib/src/System/Text/UnicodeEncoding.cs b/src/libraries/System.Private.CoreLib/src/System/Text/UnicodeEncoding.cs index fc699cb342d3e..8aa15fe9158f1 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Text/UnicodeEncoding.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Text/UnicodeEncoding.cs @@ -147,7 +147,7 @@ public override unsafe int GetBytes(string s!!, int charIndex, int charCount, throw new ArgumentOutOfRangeException(nameof(s), SR.ArgumentOutOfRange_IndexCount); if (byteIndex < 0 || byteIndex > bytes.Length) - throw new ArgumentOutOfRangeException(nameof(byteIndex), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(byteIndex), SR.ArgumentOutOfRange_IndexMustBeLessOrEqual); int byteCount = bytes.Length - byteIndex; @@ -180,7 +180,7 @@ public override unsafe int GetBytes(char[] chars!!, int charIndex, int charCount throw new ArgumentOutOfRangeException(nameof(chars), SR.ArgumentOutOfRange_IndexCountBuffer); if (byteIndex < 0 || byteIndex > bytes.Length) - throw new ArgumentOutOfRangeException(nameof(byteIndex), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(byteIndex), SR.ArgumentOutOfRange_IndexMustBeLessOrEqual); // If nothing to encode return 0, avoid fixed problem if (charCount == 0) @@ -264,7 +264,7 @@ public override unsafe int GetChars(byte[] bytes!!, int byteIndex, int byteCount throw new ArgumentOutOfRangeException(nameof(bytes), SR.ArgumentOutOfRange_IndexCountBuffer); if (charIndex < 0 || charIndex > chars.Length) - throw new ArgumentOutOfRangeException(nameof(charIndex), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(charIndex), SR.ArgumentOutOfRange_IndexMustBeLessOrEqual); // If no input, return 0 & avoid fixed problem if (byteCount == 0) diff --git a/src/libraries/System.Private.CoreLib/src/System/ThrowHelper.cs b/src/libraries/System.Private.CoreLib/src/System/ThrowHelper.cs index c743da99dfcd8..b11ff9905c547 100644 --- a/src/libraries/System.Private.CoreLib/src/System/ThrowHelper.cs +++ b/src/libraries/System.Private.CoreLib/src/System/ThrowHelper.cs @@ -99,10 +99,16 @@ internal static void ThrowArgumentException_TupleIncorrectType(object obj) } [DoesNotReturn] - internal static void ThrowArgumentOutOfRange_IndexException() + internal static void ThrowArgumentOutOfRange_IndexMustBeLessException() { throw GetArgumentOutOfRangeException(ExceptionArgument.index, - ExceptionResource.ArgumentOutOfRange_Index); + ExceptionResource.ArgumentOutOfRange_IndexMustBeLess); + } + [DoesNotReturn] + internal static void ThrowArgumentOutOfRange_IndexMustBeLessOrEqualException() + { + throw GetArgumentOutOfRangeException(ExceptionArgument.index, + ExceptionResource.ArgumentOutOfRange_IndexMustBeLessOrEqual); } [DoesNotReturn] @@ -133,10 +139,17 @@ internal static void ThrowLengthArgumentOutOfRange_ArgumentOutOfRange_NeedNonNeg } [DoesNotReturn] - internal static void ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index() + internal static void ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_IndexMustBeLessOrEqual() + { + throw GetArgumentOutOfRangeException(ExceptionArgument.startIndex, + ExceptionResource.ArgumentOutOfRange_IndexMustBeLessOrEqual); + } + + [DoesNotReturn] + internal static void ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_IndexMustBeLess() { throw GetArgumentOutOfRangeException(ExceptionArgument.startIndex, - ExceptionResource.ArgumentOutOfRange_Index); + ExceptionResource.ArgumentOutOfRange_IndexMustBeLess); } [DoesNotReturn] @@ -903,8 +916,10 @@ private static string GetResourceString(ExceptionResource resource) { switch (resource) { - case ExceptionResource.ArgumentOutOfRange_Index: - return SR.ArgumentOutOfRange_Index; + case ExceptionResource.ArgumentOutOfRange_IndexMustBeLessOrEqual: + return SR.ArgumentOutOfRange_IndexMustBeLessOrEqual; + case ExceptionResource.ArgumentOutOfRange_IndexMustBeLess: + return SR.ArgumentOutOfRange_IndexMustBeLess; case ExceptionResource.ArgumentOutOfRange_IndexCount: return SR.ArgumentOutOfRange_IndexCount; case ExceptionResource.ArgumentOutOfRange_IndexCountBuffer: @@ -1158,7 +1173,8 @@ internal enum ExceptionArgument // internal enum ExceptionResource { - ArgumentOutOfRange_Index, + ArgumentOutOfRange_IndexMustBeLessOrEqual, + ArgumentOutOfRange_IndexMustBeLess, ArgumentOutOfRange_IndexCount, ArgumentOutOfRange_IndexCountBuffer, ArgumentOutOfRange_Count, diff --git a/src/libraries/System.Security.Cryptography.Pkcs/src/Resources/Strings.resx b/src/libraries/System.Security.Cryptography.Pkcs/src/Resources/Strings.resx index c85300da29d68..2bdcfe05da60d 100644 --- a/src/libraries/System.Security.Cryptography.Pkcs/src/Resources/Strings.resx +++ b/src/libraries/System.Security.Cryptography.Pkcs/src/Resources/Strings.resx @@ -79,9 +79,12 @@ The RSA padding must be Pkcs1 or Pss. - + Index was out of range. Must be non-negative and less than the size of the collection. + + Index was out of range. Must be non-negative and less than or equal to the size of the collection. + Positive number required. diff --git a/src/libraries/System.Security.Cryptography.Pkcs/src/System/Security/Cryptography/CryptographicAttributeObjectCollection.cs b/src/libraries/System.Security.Cryptography.Pkcs/src/System/Security/Cryptography/CryptographicAttributeObjectCollection.cs index 3d70d4f809227..bdd093252bb6e 100644 --- a/src/libraries/System.Security.Cryptography.Pkcs/src/System/Security/Cryptography/CryptographicAttributeObjectCollection.cs +++ b/src/libraries/System.Security.Cryptography.Pkcs/src/System/Security/Cryptography/CryptographicAttributeObjectCollection.cs @@ -123,7 +123,7 @@ void ICollection.CopyTo(Array array!!, int index) if (array.Rank != 1) throw new ArgumentException(SR.Arg_RankMultiDimNotSupported); if (index < 0 || index >= array.Length) - throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_IndexMustBeLess); if (index > array.Length - Count) throw new ArgumentException(SR.Argument_InvalidOffLen); @@ -137,7 +137,7 @@ void ICollection.CopyTo(Array array!!, int index) public void CopyTo(CryptographicAttributeObject[] array!!, int index) { if (index < 0 || index >= array.Length) - throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_IndexMustBeLess); if (index > array.Length - Count) throw new ArgumentException(SR.Argument_InvalidOffLen); diff --git a/src/libraries/System.Security.Cryptography.Pkcs/src/System/Security/Cryptography/Pkcs/CmsRecipientCollection.cs b/src/libraries/System.Security.Cryptography.Pkcs/src/System/Security/Cryptography/Pkcs/CmsRecipientCollection.cs index 0e65973e311b2..aa84503383a7f 100644 --- a/src/libraries/System.Security.Cryptography.Pkcs/src/System/Security/Cryptography/Pkcs/CmsRecipientCollection.cs +++ b/src/libraries/System.Security.Cryptography.Pkcs/src/System/Security/Cryptography/Pkcs/CmsRecipientCollection.cs @@ -39,7 +39,7 @@ public CmsRecipient this[int index] get { if (index < 0 || index >= _recipients.Count) - throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_IndexMustBeLess); return _recipients[index]; } @@ -80,7 +80,7 @@ public void CopyTo(Array array!!, int index) if (array.Rank != 1) throw new ArgumentException(SR.Arg_RankMultiDimNotSupported); if (index < 0 || index >= array.Length) - throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_IndexMustBeLess); if (index > array.Length - Count) throw new ArgumentException(SR.Argument_InvalidOffLen); @@ -94,7 +94,7 @@ public void CopyTo(Array array!!, int index) public void CopyTo(CmsRecipient[] array!!, int index) { if (index < 0 || index >= array.Length) - throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_IndexMustBeLess); if (index > array.Length - Count) throw new ArgumentException(SR.Argument_InvalidOffLen); diff --git a/src/libraries/System.Security.Cryptography.Pkcs/src/System/Security/Cryptography/Pkcs/RecipientInfoCollection.cs b/src/libraries/System.Security.Cryptography.Pkcs/src/System/Security/Cryptography/Pkcs/RecipientInfoCollection.cs index bbf8a92377b65..d4058866d3c75 100644 --- a/src/libraries/System.Security.Cryptography.Pkcs/src/System/Security/Cryptography/Pkcs/RecipientInfoCollection.cs +++ b/src/libraries/System.Security.Cryptography.Pkcs/src/System/Security/Cryptography/Pkcs/RecipientInfoCollection.cs @@ -31,7 +31,7 @@ public RecipientInfo this[int index] get { if (index < 0 || index >= _recipientInfos.Length) - throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_IndexMustBeLess); return _recipientInfos[index]; } } @@ -59,7 +59,7 @@ public void CopyTo(Array array!!, int index) if (array.Rank != 1) throw new ArgumentException(SR.Arg_RankMultiDimNotSupported); if (index < 0 || index >= array.Length) - throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_IndexMustBeLess); if (index > array.Length - Count) throw new ArgumentException(SR.Argument_InvalidOffLen); for (int i = 0; i < Count; i++) @@ -72,7 +72,7 @@ public void CopyTo(Array array!!, int index) public void CopyTo(RecipientInfo[] array!!, int index) { if (index < 0 || index >= array.Length) - throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_IndexMustBeLess); _recipientInfos.CopyTo(array, index); } diff --git a/src/libraries/System.Security.Cryptography.Pkcs/src/System/Security/Cryptography/Pkcs/SignedCms.cs b/src/libraries/System.Security.Cryptography.Pkcs/src/System/Security/Cryptography/Pkcs/SignedCms.cs index 1aa378e114048..459411ce51d40 100644 --- a/src/libraries/System.Security.Cryptography.Pkcs/src/System/Security/Cryptography/Pkcs/SignedCms.cs +++ b/src/libraries/System.Security.Cryptography.Pkcs/src/System/Security/Cryptography/Pkcs/SignedCms.cs @@ -389,7 +389,7 @@ public void RemoveSignature(int index) if (index < 0 || index >= _signedData.SignerInfos.Length) { - throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_IndexMustBeLess); } AlgorithmIdentifierAsn signerAlgorithm = _signedData.SignerInfos[index].DigestAlgorithm; diff --git a/src/libraries/System.Security.Cryptography.Pkcs/src/System/Security/Cryptography/Pkcs/SignerInfoCollection.cs b/src/libraries/System.Security.Cryptography.Pkcs/src/System/Security/Cryptography/Pkcs/SignerInfoCollection.cs index fabde3dedb6a0..0c335a10aa3e2 100644 --- a/src/libraries/System.Security.Cryptography.Pkcs/src/System/Security/Cryptography/Pkcs/SignerInfoCollection.cs +++ b/src/libraries/System.Security.Cryptography.Pkcs/src/System/Security/Cryptography/Pkcs/SignerInfoCollection.cs @@ -56,7 +56,7 @@ public void CopyTo(Array array!!, int index) if (array.Rank != 1) throw new ArgumentException(SR.Arg_RankMultiDimNotSupported, nameof(array)); if (index < 0 || index >= array.Length) - throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_IndexMustBeLess); if (index + Count > array.Length) throw new ArgumentException(SR.Argument_InvalidOffLen); diff --git a/src/libraries/System.Security.Cryptography.Xml/src/Resources/Strings.resx b/src/libraries/System.Security.Cryptography.Xml/src/Resources/Strings.resx index e9705820b5d23..78697d97f96f9 100644 --- a/src/libraries/System.Security.Cryptography.Xml/src/Resources/Strings.resx +++ b/src/libraries/System.Security.Cryptography.Xml/src/Resources/Strings.resx @@ -117,9 +117,12 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + Index was out of range. Must be non-negative and less than the size of the collection. + + Index was out of range. Must be non-negative and less than or equal to the size of the collection. + String cannot be empty or null. diff --git a/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/TransformChain.cs b/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/TransformChain.cs index 2b208fda41a54..a890e4073b341 100644 --- a/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/TransformChain.cs +++ b/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/TransformChain.cs @@ -51,7 +51,7 @@ public Transform this[int index] get { if (index >= _transforms.Count) - throw new ArgumentException(SR.ArgumentOutOfRange_Index, nameof(index)); + throw new ArgumentException(SR.ArgumentOutOfRange_IndexMustBeLess, nameof(index)); return (Transform)_transforms[index]; } } diff --git a/src/libraries/System.Security.Cryptography/src/Resources/Strings.resx b/src/libraries/System.Security.Cryptography/src/Resources/Strings.resx index c96dca0819b91..d24791008c25f 100644 --- a/src/libraries/System.Security.Cryptography/src/Resources/Strings.resx +++ b/src/libraries/System.Security.Cryptography/src/Resources/Strings.resx @@ -144,9 +144,12 @@ The country or region code must be exactly two characters and contain characters between A through Z, inclusive. - + Index was out of range. Must be non-negative and less than the size of the collection. + + Index was out of range. Must be non-negative and less than or equal to the size of the collection. + Non-negative number required. diff --git a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/AsnEncodedDataCollection.cs b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/AsnEncodedDataCollection.cs index 396fc8447e35b..3a26812da74d8 100644 --- a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/AsnEncodedDataCollection.cs +++ b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/AsnEncodedDataCollection.cs @@ -64,7 +64,7 @@ void ICollection.CopyTo(Array array!!, int index) if (array.Rank != 1) throw new ArgumentException(SR.Arg_RankMultiDimNotSupported); if (index < 0 || index >= array.Length) - throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_IndexMustBeLess); if (Count > array.Length - index) throw new ArgumentException(SR.Argument_InvalidOffLen); @@ -81,7 +81,7 @@ public void CopyTo(AsnEncodedData[] array!!, int index) // ArgumentOutOfRangeException where List<>.CopyTo() throws ArgumentException. if (index < 0 || index >= array.Length) - throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_IndexMustBeLess); _list.CopyTo(array, index); } diff --git a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/OidCollection.cs b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/OidCollection.cs index 56c0c0c42d46f..4817a86e47b1e 100644 --- a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/OidCollection.cs +++ b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/OidCollection.cs @@ -71,7 +71,7 @@ void ICollection.CopyTo(Array array!!, int index) if (array.Rank != 1) throw new ArgumentException(SR.Arg_RankMultiDimNotSupported); if (index < 0 || index >= array.Length) - throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_IndexMustBeLess); if (index + Count > array.Length) throw new ArgumentException(SR.Argument_InvalidOffLen); @@ -87,7 +87,7 @@ public void CopyTo(Oid[] array!!, int index) // Need to do part of the argument validation ourselves as OidCollection throws // ArgumentOutOfRangeException where List<>.CopyTo() throws ArgumentException. if (index < 0 || index >= array.Length) - throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_IndexMustBeLess); Array.Copy(_oids, 0, array, index, _count); } diff --git a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/X509ChainElementCollection.cs b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/X509ChainElementCollection.cs index b7a703b8f28d0..c8aae17f6b005 100644 --- a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/X509ChainElementCollection.cs +++ b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/X509ChainElementCollection.cs @@ -44,7 +44,7 @@ public X509ChainElement this[int index] if (index < 0) throw new InvalidOperationException(SR.InvalidOperation_EnumNotStarted); if (index >= _elements.Length) - throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_IndexMustBeLess); return _elements[index]; } @@ -60,7 +60,7 @@ void ICollection.CopyTo(Array array!!, int index) if (array.Rank != 1) throw new ArgumentException(SR.Arg_RankMultiDimNotSupported); if (index < 0 || index >= array.Length) - throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_IndexMustBeLess); if (index + Count > array.Length) throw new ArgumentException(SR.Argument_InvalidOffLen); diff --git a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/X509ExtensionCollection.cs b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/X509ExtensionCollection.cs index d564b065fcb57..44efeb6139a81 100644 --- a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/X509ExtensionCollection.cs +++ b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/X509ExtensionCollection.cs @@ -42,7 +42,7 @@ public X509Extension this[int index] if (index < 0) throw new InvalidOperationException(SR.InvalidOperation_EnumNotStarted); if (index >= _list.Count) - throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_IndexMustBeLess); return _list[index]; } @@ -78,7 +78,7 @@ void ICollection.CopyTo(Array array!!, int index) if (array.Rank != 1) throw new ArgumentException(SR.Arg_RankMultiDimNotSupported); if (index < 0 || index >= array.Length) - throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_IndexMustBeLess); if (index + Count > array.Length) throw new ArgumentException(SR.Argument_InvalidOffLen); diff --git a/src/libraries/System.Text.Encoding.CodePages/src/Resources/Strings.resx b/src/libraries/System.Text.Encoding.CodePages/src/Resources/Strings.resx index 0d7fabd0bd9e1..04b0be942b65e 100644 --- a/src/libraries/System.Text.Encoding.CodePages/src/Resources/Strings.resx +++ b/src/libraries/System.Text.Encoding.CodePages/src/Resources/Strings.resx @@ -99,9 +99,12 @@ {0} is not a supported code page. - + Index was out of range. Must be non-negative and less than the size of the collection. + + Index was out of range. Must be non-negative and less than or equal to the size of the collection. + Could not find a resource entry for the encoding codepage '{0} - {1}' diff --git a/src/libraries/System.Text.Encoding.CodePages/src/System/Text/DecoderNLS.cs b/src/libraries/System.Text.Encoding.CodePages/src/System/Text/DecoderNLS.cs index 081cdd059685d..c9f6a03d8e960 100644 --- a/src/libraries/System.Text.Encoding.CodePages/src/System/Text/DecoderNLS.cs +++ b/src/libraries/System.Text.Encoding.CodePages/src/System/Text/DecoderNLS.cs @@ -130,7 +130,7 @@ public override unsafe int GetChars(byte[] bytes!!, int byteIndex, int byteCount throw new ArgumentOutOfRangeException(nameof(bytes), SR.ArgumentOutOfRange_IndexCountBuffer); if (charIndex < 0 || charIndex > chars.Length) - throw new ArgumentOutOfRangeException(nameof(charIndex), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(charIndex), SR.ArgumentOutOfRange_IndexMustBeLessOrEqual); // Avoid empty input fixed problem if (bytes.Length == 0) diff --git a/src/libraries/System.Text.Encoding.CodePages/src/System/Text/EncoderNLS.cs b/src/libraries/System.Text.Encoding.CodePages/src/System/Text/EncoderNLS.cs index f530af9d69087..974715b9ef8e4 100644 --- a/src/libraries/System.Text.Encoding.CodePages/src/System/Text/EncoderNLS.cs +++ b/src/libraries/System.Text.Encoding.CodePages/src/System/Text/EncoderNLS.cs @@ -123,7 +123,7 @@ public override unsafe int GetBytes(char[] chars!!, int charIndex, int charCount throw new ArgumentOutOfRangeException(nameof(chars), SR.ArgumentOutOfRange_IndexCountBuffer); if (byteIndex < 0 || byteIndex > bytes.Length) - throw new ArgumentOutOfRangeException(nameof(byteIndex), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(byteIndex), SR.ArgumentOutOfRange_IndexMustBeLessOrEqual); if (chars.Length == 0) chars = new char[1]; diff --git a/src/libraries/System.Text.Encoding.CodePages/src/System/Text/EncodingNLS.cs b/src/libraries/System.Text.Encoding.CodePages/src/System/Text/EncodingNLS.cs index 154f5593830db..9a2d1be7da703 100644 --- a/src/libraries/System.Text.Encoding.CodePages/src/System/Text/EncodingNLS.cs +++ b/src/libraries/System.Text.Encoding.CodePages/src/System/Text/EncodingNLS.cs @@ -98,7 +98,7 @@ public override unsafe int GetBytes(string s!!, int charIndex, int charCount, throw new ArgumentOutOfRangeException(nameof(s), SR.ArgumentOutOfRange_IndexCount); if (byteIndex < 0 || byteIndex > bytes.Length) - throw new ArgumentOutOfRangeException(nameof(byteIndex), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(byteIndex), SR.ArgumentOutOfRange_IndexMustBeLessOrEqual); int byteCount = bytes.Length - byteIndex; @@ -135,7 +135,7 @@ public override unsafe int GetBytes(char[] chars!!, int charIndex, int charCount throw new ArgumentOutOfRangeException(nameof(chars), SR.ArgumentOutOfRange_IndexCountBuffer); if (byteIndex < 0 || byteIndex > bytes.Length) - throw new ArgumentOutOfRangeException(nameof(byteIndex), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(byteIndex), SR.ArgumentOutOfRange_IndexMustBeLessOrEqual); // If nothing to encode return 0, avoid fixed problem if (chars.Length == 0) @@ -215,7 +215,7 @@ public override unsafe int GetChars(byte[] bytes!!, int byteIndex, int byteCount throw new ArgumentOutOfRangeException(nameof(bytes), SR.ArgumentOutOfRange_IndexCountBuffer); if (charIndex < 0 || charIndex > chars.Length) - throw new ArgumentOutOfRangeException(nameof(charIndex), SR.ArgumentOutOfRange_Index); + throw new ArgumentOutOfRangeException(nameof(charIndex), SR.ArgumentOutOfRange_IndexMustBeLessOrEqual); // If no input, return 0 & avoid fixed problem if (bytes.Length == 0) diff --git a/src/mono/System.Private.CoreLib/src/System/Array.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Array.Mono.cs index 024816c048f65..9bdabb7a9ac94 100644 --- a/src/mono/System.Private.CoreLib/src/System/Array.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Array.Mono.cs @@ -451,7 +451,7 @@ internal void InternalArray__ICollection_CopyTo(T[] array, int arrayIndex) internal T InternalArray__IReadOnlyList_get_Item(int index) { if ((uint)index >= (uint)Length) - ThrowHelper.ThrowArgumentOutOfRange_IndexException(); + ThrowHelper.ThrowArgumentOutOfRange_IndexMustBeLessException(); T value; // Do not change this to call GetGenericValue_icall directly, due to special casing in the runtime. @@ -482,7 +482,7 @@ internal int InternalArray__IndexOf(T item) internal T InternalArray__get_Item(int index) { if ((uint)index >= (uint)Length) - ThrowHelper.ThrowArgumentOutOfRange_IndexException(); + ThrowHelper.ThrowArgumentOutOfRange_IndexMustBeLessException(); T value; // Do not change this to call GetGenericValue_icall directly, due to special casing in the runtime. @@ -493,7 +493,7 @@ internal T InternalArray__get_Item(int index) internal void InternalArray__set_Item(int index, T item) { if ((uint)index >= (uint)Length) - ThrowHelper.ThrowArgumentOutOfRange_IndexException(); + ThrowHelper.ThrowArgumentOutOfRange_IndexMustBeLessException(); if (this is object?[] oarray) {