Array<T> exceptions to ThrowHelper (#7059)
authorBen Adams <thundercat@illyriad.co.uk>
Tue, 6 Sep 2016 18:14:42 +0000 (19:14 +0100)
committerJan Kotas <jkotas@microsoft.com>
Tue, 6 Sep 2016 18:14:42 +0000 (11:14 -0700)
src/mscorlib/src/System/Array.cs
src/mscorlib/src/System/Internal.cs
src/mscorlib/src/System/ThrowHelper.cs

index a97ce9d..0879049 100644 (file)
@@ -34,7 +34,7 @@ namespace System {
 
         public static ReadOnlyCollection<T> AsReadOnly<T>(T[] array) {
             if (array == null) {
-                throw new ArgumentNullException("array");                
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);                
             }
             Contract.Ensures(Contract.Result<ReadOnlyCollection<T>>() != null);
 
@@ -45,7 +45,7 @@ namespace System {
         [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
         public static void Resize<T>(ref T[] array, int newSize) {
             if (newSize < 0)
-                throw new ArgumentOutOfRangeException("newSize", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
+                ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.newSize, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
             Contract.Ensures(Contract.ValueAtReturn(out array) != null);
             Contract.Ensures(Contract.ValueAtReturn(out array).Length == newSize);
             Contract.EndContractBlock();
@@ -68,9 +68,9 @@ namespace System {
         public unsafe static Array CreateInstance(Type elementType, int length)
         {
             if ((object)elementType == null)
-                throw new ArgumentNullException("elementType");
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.elementType);
             if (length < 0)
-                throw new ArgumentOutOfRangeException("length", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
+                ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.length, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
             Contract.Ensures(Contract.Result<Array>() != null);
             Contract.Ensures(Contract.Result<Array>().Length == length);
             Contract.Ensures(Contract.Result<Array>().Rank == 1);
@@ -78,7 +78,7 @@ namespace System {
 
             RuntimeType t = elementType.UnderlyingSystemType as RuntimeType;
             if (t == null)
-                throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"),"elementType");
+                ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_MustBeType, ExceptionArgument.elementType);
             return InternalCreate((void*)t.TypeHandle.Value,1,&length,null);
         }
         
@@ -86,9 +86,11 @@ namespace System {
         public unsafe static Array CreateInstance(Type elementType, int length1, int length2)
         {
             if ((object)elementType == null)
-                throw new ArgumentNullException("elementType");
-            if (length1 < 0 || length2 < 0)
-                throw new ArgumentOutOfRangeException((length1 < 0 ? "length1" : "length2"), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.elementType);
+            if (length1 < 0)
+                ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.length1, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
+            if (length2 < 0)
+                ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.length2, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
             Contract.Ensures(Contract.Result<Array>() != null);
             Contract.Ensures(Contract.Result<Array>().Rank == 2);
             Contract.Ensures(Contract.Result<Array>().GetLength(0) == length1);
@@ -96,7 +98,7 @@ namespace System {
 
             RuntimeType t = elementType.UnderlyingSystemType as RuntimeType;
             if (t == null)
-                throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"),"elementType");
+                ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_MustBeType, ExceptionArgument.elementType);
             int* pLengths = stackalloc int[2];
             pLengths[0] = length1;
             pLengths[1] = length2;
@@ -107,13 +109,13 @@ namespace System {
         public unsafe static Array CreateInstance(Type elementType, int length1, int length2, int length3)
         {
             if ((object)elementType == null)
-                throw new ArgumentNullException("elementType");
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.elementType);
             if (length1 < 0)
-                throw new ArgumentOutOfRangeException("length1", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
+                ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.length1, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
             if (length2 < 0)
-                throw new ArgumentOutOfRangeException("length2", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
+                ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.length2, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
             if (length3 < 0)
-                throw new ArgumentOutOfRangeException("length3", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
+                ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.length3, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
             Contract.Ensures(Contract.Result<Array>() != null);
             Contract.Ensures(Contract.Result<Array>().Rank == 3);
             Contract.Ensures(Contract.Result<Array>().GetLength(0) == length1);
@@ -122,7 +124,7 @@ namespace System {
 
             RuntimeType t = elementType.UnderlyingSystemType as RuntimeType;
             if (t == null)
-                throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"), "elementType");
+                ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_MustBeType, ExceptionArgument.elementType);
             int* pLengths = stackalloc int[3];
             pLengths[0] = length1;
             pLengths[1] = length2;
@@ -134,38 +136,38 @@ namespace System {
         public unsafe static Array CreateInstance(Type elementType, params int[] lengths)
         {
             if ((object)elementType == null)
-                throw new ArgumentNullException("elementType");
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.elementType);
             if (lengths == null)
-                throw new ArgumentNullException("lengths");
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.lengths);
             if (lengths.Length == 0)
-                throw new ArgumentException(Environment.GetResourceString("Arg_NeedAtLeast1Rank"));
+                ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_NeedAtLeast1Rank);
             Contract.Ensures(Contract.Result<Array>() != null);
             Contract.Ensures(Contract.Result<Array>().Rank == lengths.Length);
             Contract.EndContractBlock();
 
             RuntimeType t = elementType.UnderlyingSystemType as RuntimeType;
             if (t == null)
-                throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"), "elementType");
+                ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_MustBeType, ExceptionArgument.elementType);
 
             // Check to make sure the lenghts are all positive. Note that we check this here to give
             // a good exception message if they are not; however we check this again inside the execution 
             // engine's low level allocation function after having made a copy of the array to prevent a 
             // malicious caller from mutating the array after this check.           
-            for (int i=0;i<lengths.Length;i++)
+            for (int i = 0; i < lengths.Length; i++)
                 if (lengths[i] < 0)
-                    throw new ArgumentOutOfRangeException("lengths["+i+']', Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
-                
-            fixed(int* pLengths = lengths)
+                    ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.lengths, i, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
+
+            fixed (int* pLengths = lengths)
                 return InternalCreate((void*)t.TypeHandle.Value,lengths.Length,pLengths,null);
         }
 
         public static Array CreateInstance(Type elementType, params long[] lengths)
         {
             if( lengths == null) {
-                throw new ArgumentNullException("lengths");                
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.lengths);
             }
             if (lengths.Length == 0)
-                throw new ArgumentException(Environment.GetResourceString("Arg_NeedAtLeast1Rank"));
+                ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_NeedAtLeast1Rank);
             Contract.Ensures(Contract.Result<Array>() != null);
             Contract.Ensures(Contract.Result<Array>().Rank == lengths.Length);
             Contract.EndContractBlock();
@@ -175,8 +177,8 @@ namespace System {
             for (int i = 0; i < lengths.Length; ++i) 
             {
                 long len = lengths[i];
-                if (len > Int32.MaxValue || len < Int32.MinValue) 
-                    throw new ArgumentOutOfRangeException("len", Environment.GetResourceString("ArgumentOutOfRange_HugeArrayNotSupported"));
+                if (len > Int32.MaxValue || len < Int32.MinValue)
+                    ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.len, ExceptionResource.ArgumentOutOfRange_HugeArrayNotSupported);
                 intLengths[i] = (int) len;
             }
 
@@ -188,22 +190,22 @@ namespace System {
         public unsafe static Array CreateInstance(Type elementType, int[] lengths,int[] lowerBounds)
         {
             if (elementType == null)
-                throw new ArgumentNullException("elementType");
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.elementType);
             if (lengths == null)
-                throw new ArgumentNullException("lengths");
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.lengths);
             if (lowerBounds == null)
-                throw new ArgumentNullException("lowerBounds");
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.lowerBounds);
             if (lengths.Length != lowerBounds.Length)
-                throw new ArgumentException(Environment.GetResourceString("Arg_RanksAndBounds"));
+                ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_RanksAndBounds);
             if (lengths.Length == 0)
-                throw new ArgumentException(Environment.GetResourceString("Arg_NeedAtLeast1Rank"));
+                ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_NeedAtLeast1Rank);
             Contract.Ensures(Contract.Result<Array>() != null);
             Contract.Ensures(Contract.Result<Array>().Rank == lengths.Length);
             Contract.EndContractBlock();
 
             RuntimeType t = elementType.UnderlyingSystemType as RuntimeType;
             if (t == null)
-                throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"), "elementType");
+                ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_MustBeType, ExceptionArgument.elementType);
 
             // Check to make sure the lenghts are all positive. Note that we check this here to give
             // a good exception message if they are not; however we check this again inside the execution 
@@ -211,9 +213,9 @@ namespace System {
             // malicious caller from mutating the array after this check.           
             for (int i=0;i<lengths.Length;i++)
                 if (lengths[i] < 0)
-                    throw new ArgumentOutOfRangeException("lengths["+i+']', Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
-                            
-            fixed(int* pLengths = lengths)
+                    ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.lengths, i, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
+
+            fixed (int* pLengths = lengths)
                 fixed(int* pLowerBounds = lowerBounds)
                     return InternalCreate((void*)t.TypeHandle.Value,lengths.Length,pLengths,pLowerBounds);
         }
@@ -265,9 +267,9 @@ namespace System {
         public static void Copy(Array sourceArray, Array destinationArray, int length)
         {
             if (sourceArray == null)
-                throw new ArgumentNullException("sourceArray");
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.sourceArray);
             if (destinationArray == null)
-                throw new ArgumentNullException("destinationArray");
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.destinationArray);
             /*
             Contract.Requires(sourceArray.Rank == destinationArray.Rank);
             Contract.Requires(length >= 0);
@@ -313,8 +315,8 @@ namespace System {
         [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
         public static void Copy(Array sourceArray, Array destinationArray, long length)
         {
-            if (length > Int32.MaxValue || length < Int32.MinValue) 
-                throw new ArgumentOutOfRangeException("length", Environment.GetResourceString("ArgumentOutOfRange_HugeArrayNotSupported"));
+            if (length > Int32.MaxValue || length < Int32.MinValue)
+                ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.length, ExceptionResource.ArgumentOutOfRange_HugeArrayNotSupported);
 
             Array.Copy(sourceArray, destinationArray, (int) length);
         }
@@ -322,12 +324,12 @@ namespace System {
         [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
         public static void Copy(Array sourceArray, long sourceIndex, Array destinationArray, long destinationIndex, long length)
         {
-            if (sourceIndex > Int32.MaxValue || sourceIndex < Int32.MinValue) 
-                throw new ArgumentOutOfRangeException("sourceIndex", Environment.GetResourceString("ArgumentOutOfRange_HugeArrayNotSupported"));
-            if (destinationIndex > Int32.MaxValue || destinationIndex < Int32.MinValue) 
-                throw new ArgumentOutOfRangeException("destinationIndex", Environment.GetResourceString("ArgumentOutOfRange_HugeArrayNotSupported"));
-            if (length > Int32.MaxValue || length < Int32.MinValue) 
-                throw new ArgumentOutOfRangeException("length", Environment.GetResourceString("ArgumentOutOfRange_HugeArrayNotSupported"));
+            if (sourceIndex > Int32.MaxValue || sourceIndex < Int32.MinValue)
+                ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.sourceIndex, ExceptionResource.ArgumentOutOfRange_HugeArrayNotSupported);
+            if (destinationIndex > Int32.MaxValue || destinationIndex < Int32.MinValue)
+                ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.destinationIndex, ExceptionResource.ArgumentOutOfRange_HugeArrayNotSupported);
+            if (length > Int32.MaxValue || length < Int32.MinValue)
+                ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.length, ExceptionResource.ArgumentOutOfRange_HugeArrayNotSupported);
 
             Array.Copy(sourceArray, (int) sourceIndex, destinationArray, (int) destinationIndex, (int) length);
         }
@@ -346,9 +348,9 @@ namespace System {
         public unsafe Object GetValue(params int[] indices)
         {
             if (indices == null)
-                throw new ArgumentNullException("indices");
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.indices);
             if (Rank != indices.Length)
-                throw new ArgumentException(Environment.GetResourceString("Arg_RankIndices"));
+                ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_RankIndices);
             Contract.EndContractBlock();
 
             TypedReference elemref = new TypedReference();
@@ -361,7 +363,7 @@ namespace System {
         public unsafe Object GetValue(int index)
         {
             if (Rank != 1)
-                throw new ArgumentException(Environment.GetResourceString("Arg_Need1DArray"));
+                ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_Need1DArray);
             Contract.EndContractBlock();
 
             TypedReference elemref = new TypedReference();
@@ -373,7 +375,7 @@ namespace System {
         public unsafe Object GetValue(int index1, int index2)
         {
             if (Rank != 2)
-                throw new ArgumentException(Environment.GetResourceString("Arg_Need2DArray"));
+                ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_Need2DArray);
             Contract.EndContractBlock();
 
             int* pIndices = stackalloc int[2];
@@ -389,7 +391,7 @@ namespace System {
         public unsafe Object GetValue(int index1, int index2, int index3)
         {
             if (Rank != 3)
-                throw new ArgumentException(Environment.GetResourceString("Arg_Need3DArray"));
+                ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_Need3DArray);
             Contract.EndContractBlock();
 
             int* pIndices = stackalloc int[3];
@@ -405,8 +407,8 @@ namespace System {
         [ComVisible(false)]       
         public Object GetValue(long index)
         {
-            if (index > Int32.MaxValue || index < Int32.MinValue) 
-                throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_HugeArrayNotSupported"));
+            if (index > Int32.MaxValue || index < Int32.MinValue)
+                ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_HugeArrayNotSupported);
             Contract.EndContractBlock();
 
             return this.GetValue((int) index);
@@ -415,10 +417,10 @@ namespace System {
         [ComVisible(false)]
         public Object GetValue(long index1, long index2)
         {
-            if (index1 > Int32.MaxValue || index1 < Int32.MinValue) 
-                throw new ArgumentOutOfRangeException("index1", Environment.GetResourceString("ArgumentOutOfRange_HugeArrayNotSupported"));
-            if (index2 > Int32.MaxValue || index2 < Int32.MinValue) 
-                throw new ArgumentOutOfRangeException("index2", Environment.GetResourceString("ArgumentOutOfRange_HugeArrayNotSupported"));
+            if (index1 > Int32.MaxValue || index1 < Int32.MinValue)
+                ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index1, ExceptionResource.ArgumentOutOfRange_HugeArrayNotSupported);
+            if (index2 > Int32.MaxValue || index2 < Int32.MinValue)
+                ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index2, ExceptionResource.ArgumentOutOfRange_HugeArrayNotSupported);
             Contract.EndContractBlock();
 
             return this.GetValue((int) index1, (int) index2);
@@ -427,12 +429,12 @@ namespace System {
         [ComVisible(false)]
         public Object GetValue(long index1, long index2, long index3)
         {
-            if (index1 > Int32.MaxValue || index1 < Int32.MinValue) 
-                throw new ArgumentOutOfRangeException("index1", Environment.GetResourceString("ArgumentOutOfRange_HugeArrayNotSupported"));
-            if (index2 > Int32.MaxValue || index2 < Int32.MinValue) 
-                throw new ArgumentOutOfRangeException("index2", Environment.GetResourceString("ArgumentOutOfRange_HugeArrayNotSupported"));
-            if (index3 > Int32.MaxValue || index3 < Int32.MinValue) 
-                throw new ArgumentOutOfRangeException("index3", Environment.GetResourceString("ArgumentOutOfRange_HugeArrayNotSupported"));
+            if (index1 > Int32.MaxValue || index1 < Int32.MinValue)
+                ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index1, ExceptionResource.ArgumentOutOfRange_HugeArrayNotSupported);
+            if (index2 > Int32.MaxValue || index2 < Int32.MinValue)
+                ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index2, ExceptionResource.ArgumentOutOfRange_HugeArrayNotSupported);
+            if (index3 > Int32.MaxValue || index3 < Int32.MinValue)
+                ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index3, ExceptionResource.ArgumentOutOfRange_HugeArrayNotSupported);
             Contract.EndContractBlock();
             
             return this.GetValue((int) index1, (int) index2, (int) index3);
@@ -442,9 +444,9 @@ namespace System {
         public Object GetValue(params long[] indices)
         {
             if (indices == null)
-                throw new ArgumentNullException("indices");
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.indices);
             if (Rank != indices.Length)
-                throw new ArgumentException(Environment.GetResourceString("Arg_RankIndices"));
+                ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_RankIndices);
             Contract.EndContractBlock();
 
             int[] intIndices = new int[indices.Length];
@@ -452,8 +454,8 @@ namespace System {
             for (int i = 0; i < indices.Length; ++i) 
             {
                 long index = indices[i];
-                if (index > Int32.MaxValue || index < Int32.MinValue) 
-                    throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_HugeArrayNotSupported"));
+                if (index > Int32.MaxValue || index < Int32.MinValue)
+                    ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_HugeArrayNotSupported);
                 intIndices[i] = (int) index;
             }
 
@@ -465,7 +467,7 @@ namespace System {
         public unsafe void SetValue(Object value,int index)
         {
             if (Rank != 1)
-                throw new ArgumentException(Environment.GetResourceString("Arg_Need1DArray"));
+                ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_Need1DArray);
             Contract.EndContractBlock();
 
             TypedReference elemref = new TypedReference();
@@ -477,7 +479,7 @@ namespace System {
         public unsafe void SetValue(Object value,int index1, int index2)
         {
             if (Rank != 2)
-                throw new ArgumentException(Environment.GetResourceString("Arg_Need2DArray"));
+                ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_Need2DArray);
             Contract.EndContractBlock();
 
             int* pIndices = stackalloc int[2];
@@ -493,7 +495,7 @@ namespace System {
         public unsafe void SetValue(Object value,int index1, int index2, int index3)
         {
             if (Rank != 3)
-                throw new ArgumentException(Environment.GetResourceString("Arg_Need3DArray"));
+                ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_Need3DArray);
             Contract.EndContractBlock();
 
             int* pIndices = stackalloc int[3];
@@ -510,9 +512,9 @@ namespace System {
         public unsafe void SetValue(Object value,params int[] indices)
         {
             if (indices == null)
-                throw new ArgumentNullException("indices");
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.indices);
             if (Rank != indices.Length)
-                throw new ArgumentException(Environment.GetResourceString("Arg_RankIndices"));
+                ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_RankIndices);
             Contract.EndContractBlock();
 
             TypedReference elemref = new TypedReference();
@@ -524,8 +526,8 @@ namespace System {
         [ComVisible(false)]
         public void SetValue(Object value, long index)
         {
-            if (index > Int32.MaxValue || index < Int32.MinValue) 
-                throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_HugeArrayNotSupported"));
+            if (index > Int32.MaxValue || index < Int32.MinValue)
+                ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_HugeArrayNotSupported);
             Contract.EndContractBlock();
 
             this.SetValue(value, (int) index);
@@ -534,10 +536,10 @@ namespace System {
         [ComVisible(false)]
         public void SetValue(Object value, long index1, long index2)
         {
-            if (index1 > Int32.MaxValue || index1 < Int32.MinValue) 
-                throw new ArgumentOutOfRangeException("index1", Environment.GetResourceString("ArgumentOutOfRange_HugeArrayNotSupported"));
-            if (index2 > Int32.MaxValue || index2 < Int32.MinValue) 
-                throw new ArgumentOutOfRangeException("index2", Environment.GetResourceString("ArgumentOutOfRange_HugeArrayNotSupported"));
+            if (index1 > Int32.MaxValue || index1 < Int32.MinValue)
+                ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index1, ExceptionResource.ArgumentOutOfRange_HugeArrayNotSupported);
+            if (index2 > Int32.MaxValue || index2 < Int32.MinValue)
+                ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index2, ExceptionResource.ArgumentOutOfRange_HugeArrayNotSupported);
             Contract.EndContractBlock();
 
             this.SetValue(value, (int) index1, (int) index2);
@@ -546,12 +548,12 @@ namespace System {
         [ComVisible(false)]
         public void SetValue(Object value, long index1, long index2, long index3)
         {
-            if (index1 > Int32.MaxValue || index1 < Int32.MinValue) 
-                throw new ArgumentOutOfRangeException("index1", Environment.GetResourceString("ArgumentOutOfRange_HugeArrayNotSupported"));
-            if (index2 > Int32.MaxValue || index2 < Int32.MinValue) 
-                throw new ArgumentOutOfRangeException("index2", Environment.GetResourceString("ArgumentOutOfRange_HugeArrayNotSupported"));
-            if (index3 > Int32.MaxValue || index3 < Int32.MinValue) 
-                throw new ArgumentOutOfRangeException("index3", Environment.GetResourceString("ArgumentOutOfRange_HugeArrayNotSupported"));
+            if (index1 > Int32.MaxValue || index1 < Int32.MinValue)
+                ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index1, ExceptionResource.ArgumentOutOfRange_HugeArrayNotSupported);
+            if (index2 > Int32.MaxValue || index2 < Int32.MinValue)
+                ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index2, ExceptionResource.ArgumentOutOfRange_HugeArrayNotSupported);
+            if (index3 > Int32.MaxValue || index3 < Int32.MinValue)
+                ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index3, ExceptionResource.ArgumentOutOfRange_HugeArrayNotSupported);
             Contract.EndContractBlock();
 
             this.SetValue(value, (int) index1, (int) index2, (int) index3);
@@ -561,9 +563,9 @@ namespace System {
         public void SetValue(Object value, params long[] indices)
         {
             if (indices == null)
-                throw new ArgumentNullException("indices");
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.indices);
             if (Rank != indices.Length)
-                throw new ArgumentException(Environment.GetResourceString("Arg_RankIndices"));
+                ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_RankIndices);
             Contract.EndContractBlock();
 
             int[] intIndices = new int[indices.Length];
@@ -571,8 +573,8 @@ namespace System {
             for (int i = 0; i < indices.Length; ++i) 
             {
                 long index = indices[i];
-                if (index > Int32.MaxValue || index < Int32.MinValue) 
-                    throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_HugeArrayNotSupported"));
+                if (index > Int32.MaxValue || index < Int32.MinValue)
+                    ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_HugeArrayNotSupported);
                 intIndices[i] = (int) index;
             }
 
@@ -693,7 +695,8 @@ namespace System {
 
         int IList.Add(Object value)
         {
-            throw new NotSupportedException(Environment.GetResourceString("NotSupported_FixedSizeCollection"));
+            ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_FixedSizeCollection);
+            return default(int);
         }
 
         bool IList.Contains(Object value)
@@ -713,17 +716,17 @@ namespace System {
 
         void IList.Insert(int index, Object value)
         {
-            throw new NotSupportedException(Environment.GetResourceString("NotSupported_FixedSizeCollection"));
+            ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_FixedSizeCollection);
         }
 
         void IList.Remove(Object value)
         {
-            throw new NotSupportedException(Environment.GetResourceString("NotSupported_FixedSizeCollection"));
+            ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_FixedSizeCollection);
         }
 
         void IList.RemoveAt(int index)
         {
-            throw new NotSupportedException(Environment.GetResourceString("NotSupported_FixedSizeCollection"));
+            ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_FixedSizeCollection);
         }
 
         // Make a new array which is a shallow copy of the original array.
@@ -740,8 +743,9 @@ namespace System {
 
             Array o = other as Array;
 
-            if (o == null || this.Length != o.Length) {
-                throw new ArgumentException(Environment.GetResourceString("ArgumentException_OtherNotArrayOfCorrectLength"), "other");
+            if (o == null || this.Length != o.Length)
+            {
+                ThrowHelper.ThrowArgumentException(ExceptionResource.ArgumentException_OtherNotArrayOfCorrectLength, ExceptionArgument.other);
             }
 
             int i = 0;
@@ -795,7 +799,7 @@ namespace System {
 
         int IStructuralEquatable.GetHashCode(IEqualityComparer comparer) {
             if (comparer == null)
-                throw new ArgumentNullException("comparer");
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.comparer);
             Contract.EndContractBlock();
 
             int ret = 0;
@@ -824,7 +828,7 @@ namespace System {
         [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
         public static int BinarySearch(Array array, Object value) {
             if (array==null)
-                throw new ArgumentNullException("array");
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
             Contract.Ensures((Contract.Result<int>() >= array.GetLowerBound(0) && Contract.Result<int>() <= array.GetUpperBound(0)) || (Contract.Result<int>() < array.GetLowerBound(0) && ~Contract.Result<int>() <= array.GetUpperBound(0) + 1));
             Contract.EndContractBlock();
             int lb = array.GetLowerBound(0);
@@ -868,7 +872,7 @@ namespace System {
         [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
         public static int BinarySearch(Array array, Object value, IComparer comparer) {
             if (array==null)
-                throw new ArgumentNullException("array");
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
             Contract.EndContractBlock();
             int lb = array.GetLowerBound(0);
             return BinarySearch(array, lb, array.Length, value, comparer);
@@ -894,15 +898,17 @@ namespace System {
         [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
         public static int BinarySearch(Array array, int index, int length, Object value, IComparer comparer) {
             if (array==null) 
-                throw new ArgumentNullException("array");
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
             Contract.EndContractBlock();
             int lb = array.GetLowerBound(0);
-            if (index < lb || length < 0)
-                throw new ArgumentOutOfRangeException((index<lb ? "index" : "length"), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
+            if (index < lb)
+                ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException();
+            if (length < 0)
+                ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.length, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
             if (array.Length - (index - lb) < length)
-                throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen"));
+                ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidOffLen);
             if (array.Rank != 1)
-                throw new RankException(Environment.GetResourceString("Rank_MultiDimNotSupported"));
+                ThrowHelper.ThrowRankException(ExceptionResource.Rank_MultiDimNotSupported);
             
             if (comparer == null) comparer = Comparer.Default;
             if (comparer == Comparer.Default) {
@@ -920,12 +926,12 @@ namespace System {
                     // i might overflow if lo and hi are both large positive numbers. 
                     int i = GetMedian(lo, hi);
 
-                    int c;
+                    int c = 0;
                     try {
                         c = comparer.Compare(objArray[i], value);
                     }
                     catch (Exception e) {
-                        throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_IComparerFailed"), e);
+                        ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_IComparerFailed, e);
                     }
                     if (c == 0) return i;
                     if (c < 0) {
@@ -940,12 +946,12 @@ namespace System {
                 while (lo <= hi) {
                     int i = GetMedian(lo, hi);                    
 
-                    int c;
+                    int c = 0;
                     try {
                         c = comparer.Compare(array.GetValue(i), value);
                     }
                     catch (Exception e) {
-                        throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_IComparerFailed"), e);
+                        ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_IComparerFailed, e);
                     }
                     if (c == 0) return i;
                     if (c < 0) {
@@ -968,7 +974,7 @@ namespace System {
         [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
         public static int BinarySearch<T>(T[] array, T value) {
             if (array==null)
-                throw new ArgumentNullException("array");
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
             Contract.EndContractBlock();
             return BinarySearch<T>(array, 0, array.Length, value, null);
         }
@@ -977,7 +983,7 @@ namespace System {
         [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
         public static int BinarySearch<T>(T[] array, T value, System.Collections.Generic.IComparer<T> comparer) {
             if (array==null)
-                throw new ArgumentNullException("array");
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
             Contract.EndContractBlock();
             return BinarySearch<T>(array, 0, array.Length, value, comparer);
         }
@@ -992,11 +998,14 @@ namespace System {
         [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
         public static int BinarySearch<T>(T[] array, int index, int length, T value, System.Collections.Generic.IComparer<T> comparer) {
             if (array==null) 
-                throw new ArgumentNullException("array");
-            if (index < 0 || length < 0)
-                throw new ArgumentOutOfRangeException((index<0 ? "index" : "length"), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
+            if (index < 0)
+                ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException();
+            if (length < 0)
+                ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.length, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
+
             if (array.Length - index < length)
-                throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen"));
+                ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidOffLen);
             Contract.EndContractBlock();
 
             return ArraySortHelper<T>.Default.BinarySearch(array, index, length, value, comparer);
@@ -1004,11 +1013,11 @@ namespace System {
 
         public static TOutput[] ConvertAll<TInput, TOutput>(TInput[] array, Converter<TInput,TOutput> converter) {
             if( array == null) {
-                throw new ArgumentNullException("array");
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
             }
 
             if( converter == null) {
-                throw new ArgumentNullException("converter");
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.converter);
             }
             Contract.Ensures(Contract.Result<TOutput[]>() != null);
             Contract.Ensures(Contract.Result<TOutput[]>().Length == array.Length);
@@ -1032,7 +1041,7 @@ namespace System {
         public void CopyTo(Array array, int index)
         {
             if (array != null && array.Rank != 1)
-                throw new ArgumentException(Environment.GetResourceString("Arg_RankMultiDimNotSupported"));
+                ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_RankMultiDimNotSupported);
             Contract.EndContractBlock();
             // Note: Array.Copy throws a RankException and we want a consistent ArgumentException for all the IList CopyTo methods.
             Array.Copy(this, GetLowerBound(0), array, index, Length);
@@ -1042,8 +1051,8 @@ namespace System {
         [ComVisible(false)]
         public void CopyTo(Array array, long index)
         {
-            if (index > Int32.MaxValue || index < Int32.MinValue) 
-                throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_HugeArrayNotSupported"));
+            if (index > Int32.MaxValue || index < Int32.MinValue)
+                ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_HugeArrayNotSupported);
             Contract.EndContractBlock();
 
             this.CopyTo(array, (int) index);
@@ -1066,11 +1075,11 @@ namespace System {
 
         public static T Find<T>(T[] array, Predicate<T> match) {
             if( array == null) {
-                throw new ArgumentNullException("array");
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
             }
 
             if( match == null) {
-                throw new ArgumentNullException("match");
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.match);
             }
             Contract.EndContractBlock();
 
@@ -1084,11 +1093,11 @@ namespace System {
 
         public static T[] FindAll<T>(T[] array, Predicate<T> match) {
             if( array == null) {
-                throw new ArgumentNullException("array");
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
             }
 
             if( match == null) {
-                throw new ArgumentNullException("match");
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.match);
             }
             Contract.EndContractBlock();
 
@@ -1103,7 +1112,7 @@ namespace System {
 
         public static int FindIndex<T>(T[] array, Predicate<T> match) {
             if (array==null) {
-                throw new ArgumentNullException("array");
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
             }
             Contract.Ensures(Contract.Result<int>() < array.Length);
             Contract.EndContractBlock();
@@ -1113,7 +1122,7 @@ namespace System {
 
         public static int FindIndex<T>(T[] array, int startIndex, Predicate<T> match) {
             if (array==null) {
-                throw new ArgumentNullException("array");
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
             }
             Contract.Ensures(Contract.Result<int>() < array.Length);
             Contract.EndContractBlock();
@@ -1123,19 +1132,19 @@ namespace System {
 
         public static int FindIndex<T>(T[] array, int startIndex, int count, Predicate<T> match) {
             if (array==null) {
-                throw new ArgumentNullException("array");
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
             }
 
             if( startIndex < 0 || startIndex > array.Length ) {
-                throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_Index"));                
+                ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index);
             }
 
             if (count < 0 || startIndex > array.Length - count) {
-                throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_Count"));
+                ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_Count);
             }
 
             if( match == null) {
-                throw new ArgumentNullException("match");
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.match);
             }
             Contract.Ensures(Contract.Result<int>() < array.Length);
             Contract.EndContractBlock();
@@ -1149,11 +1158,11 @@ namespace System {
 
         public static T FindLast<T>(T[] array, Predicate<T> match) {
             if( array == null) {
-                throw new ArgumentNullException("array");
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
             }
 
             if( match == null) {
-                throw new ArgumentNullException("match");
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.match);
             }
             Contract.EndContractBlock();
             
@@ -1167,7 +1176,7 @@ namespace System {
 
         public static int FindLastIndex<T>(T[] array, Predicate<T> match) {
             if( array == null) {
-                throw new ArgumentNullException("array");
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
             }
             Contract.EndContractBlock();
 
@@ -1176,7 +1185,7 @@ namespace System {
 
         public static int FindLastIndex<T>(T[] array, int startIndex, Predicate<T> match) {
             if( array == null) {
-                throw new ArgumentNullException("array");
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
             }
             Contract.EndContractBlock();
         
@@ -1185,30 +1194,30 @@ namespace System {
 
         public static int FindLastIndex<T>(T[] array, int startIndex, int count, Predicate<T> match) {
             if( array == null) {
-                throw new ArgumentNullException("array");
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
             }
 
             if( match == null) {
-                throw new ArgumentNullException("match");
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.match);
             }
             Contract.EndContractBlock();
 
             if(array.Length == 0) {
                 // Special case for 0 length List
                 if( startIndex != -1) {
-                    throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_Index"));
+                    ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index);
                 }
             }
             else {
                 // Make sure we're not out of range            
                 if ( startIndex < 0 || startIndex >= array.Length) {
-                    throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_Index"));
+                    ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index);
                 }
             }
             
             // 2nd have of this also catches when startIndex == MAXINT, so MAXINT - 0 + 1 == -1, which is < 0.
             if (count < 0 || startIndex - count + 1 < 0) {
-                throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_Count"));
+                ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_Count);
             }
 
             int endIndex = startIndex - count;
@@ -1222,11 +1231,11 @@ namespace System {
 
         public static void ForEach<T>(T[] array, Action<T> action) {
             if( array == null) {
-                throw new ArgumentNullException("array");
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
             }
 
             if( action == null) {
-                throw new ArgumentNullException("action");
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.action);
             }
             Contract.EndContractBlock();
 
@@ -1255,7 +1264,7 @@ namespace System {
         [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
         public static int IndexOf(Array array, Object value) {
             if (array==null)
-                throw new ArgumentNullException("array");
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
             Contract.Ensures(Contract.Result<int>() < array.GetLowerBound(0) + array.Length);
             Contract.EndContractBlock();
             int lb = array.GetLowerBound(0);
@@ -1271,7 +1280,7 @@ namespace System {
         [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
         public static int IndexOf(Array array, Object value, int startIndex) {
             if (array==null)
-                throw new ArgumentNullException("array");
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
             Contract.Ensures(Contract.Result<int>() < array.GetLowerBound(0) + array.Length);
             Contract.EndContractBlock();
             int lb = array.GetLowerBound(0);
@@ -1288,17 +1297,17 @@ namespace System {
         [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
         public static int IndexOf(Array array, Object value, int startIndex, int count) {
             if (array==null)
-                throw new ArgumentNullException("array");
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
             if (array.Rank != 1)
-                throw new RankException(Environment.GetResourceString("Rank_MultiDimNotSupported"));
+                ThrowHelper.ThrowRankException(ExceptionResource.Rank_MultiDimNotSupported);
             Contract.Ensures(Contract.Result<int>() < array.GetLowerBound(0) + array.Length);
             Contract.EndContractBlock();
 
             int lb = array.GetLowerBound(0);
             if (startIndex < lb || startIndex > array.Length + lb)
-                throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_Index"));
+                ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index);
             if (count < 0 || count > array.Length - startIndex + lb)
-                throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_Count"));
+                ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_Count);
 
             // Try calling a quick native method to handle primitive types.
             int retVal;
@@ -1342,7 +1351,7 @@ namespace System {
         [Pure]
         public static int IndexOf<T>(T[] array, T value) {
             if (array==null) {
-                throw new ArgumentNullException("array");
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
             }
             Contract.Ensures((Contract.Result<int>() < 0) ||
                 (Contract.Result<int>() >= 0 && Contract.Result<int>() < array.Length && EqualityComparer<T>.Default.Equals(value, array[Contract.Result<int>()])));
@@ -1353,7 +1362,7 @@ namespace System {
 
         public static int IndexOf<T>(T[] array, T value, int startIndex) {
             if (array==null) {
-                throw new ArgumentNullException("array");
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
             }
             Contract.Ensures(Contract.Result<int>() < array.Length);
             Contract.EndContractBlock();
@@ -1363,15 +1372,15 @@ namespace System {
 
         public static int IndexOf<T>(T[] array, T value, int startIndex, int count) {
             if (array==null) {
-                throw new ArgumentNullException("array");
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
             }
 
             if (startIndex < 0 || startIndex > array.Length ) {
-                throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_Index"));
+                ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index);
             }
 
             if (count < 0 || count > array.Length - startIndex) {
-                throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_Count"));
+                ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_Count);
             }
             Contract.Ensures(Contract.Result<int>() < array.Length);
             Contract.EndContractBlock();
@@ -1392,7 +1401,7 @@ namespace System {
         [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
         public static int LastIndexOf(Array array, Object value) {
             if (array==null)
-                throw new ArgumentNullException("array");
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
             Contract.Ensures(Contract.Result<int>() < array.GetLowerBound(0) + array.Length);
             Contract.EndContractBlock();
             int lb = array.GetLowerBound(0);
@@ -1407,7 +1416,7 @@ namespace System {
         [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
         public static int LastIndexOf(Array array, Object value, int startIndex) {
             if (array == null)
-                throw new ArgumentNullException("array");
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
             Contract.Ensures(Contract.Result<int>() < array.GetLowerBound(0) + array.Length);
             Contract.EndContractBlock();
             int lb = array.GetLowerBound(0);
@@ -1424,7 +1433,7 @@ namespace System {
         [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
         public static int LastIndexOf(Array array, Object value, int startIndex, int count) {
             if (array==null)
-                throw new ArgumentNullException("array");
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
             Contract.Ensures(Contract.Result<int>() < array.GetLowerBound(0) + array.Length);
             Contract.EndContractBlock();
             int lb = array.GetLowerBound(0);
@@ -1433,13 +1442,13 @@ namespace System {
             }
 
             if (startIndex < lb || startIndex >= array.Length + lb)
-                throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_Index"));
+                ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index);
             if (count < 0)
-                throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_Count"));
+                ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_Count);
             if (count > startIndex - lb + 1)
-                throw new ArgumentOutOfRangeException("endIndex", Environment.GetResourceString("ArgumentOutOfRange_EndIndexStartIndex"));
+                ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.endIndex, ExceptionResource.ArgumentOutOfRange_EndIndexStartIndex);
             if (array.Rank != 1)
-                throw new RankException(Environment.GetResourceString("Rank_MultiDimNotSupported"));
+                ThrowHelper.ThrowRankException(ExceptionResource.Rank_MultiDimNotSupported);
 
             // Try calling a quick native method to handle primitive types.
             int retVal;
@@ -1478,7 +1487,7 @@ namespace System {
         
         public static int LastIndexOf<T>(T[] array, T value) {
             if (array==null) {
-                throw new ArgumentNullException("array");
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
             }
             Contract.Ensures(Contract.Result<int>() < array.Length);
             Contract.EndContractBlock();
@@ -1488,7 +1497,7 @@ namespace System {
 
         public static int LastIndexOf<T>(T[] array, T value, int startIndex) {
             if (array==null) {
-                throw new ArgumentNullException("array");
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
             }
             Contract.Ensures(Contract.Result<int>() < array.Length);
             Contract.EndContractBlock();
@@ -1498,7 +1507,7 @@ namespace System {
 
         public static int LastIndexOf<T>(T[] array, T value, int startIndex, int count) {
             if (array==null) {
-                throw new ArgumentNullException("array");
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
             }
             Contract.Ensures(Contract.Result<int>() < array.Length);
             Contract.EndContractBlock();
@@ -1509,24 +1518,24 @@ namespace System {
                 // accept -1 and 0 as valid startIndex for compablility reason.
                 //
                 if( startIndex != -1 && startIndex != 0) {
-                    throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_Index"));
+                    ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index);
                 }
 
                 // only 0 is a valid value for count if array is empty
                 if( count != 0) {
-                    throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_Count"));
+                    ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_Count);
                 }
                 return -1;
             }
 
             // Make sure we're not out of range            
             if ( startIndex < 0 || startIndex >= array.Length) {
-                throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_Index"));
+                ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index);
             }
             
             // 2nd have of this also catches when startIndex == MAXINT, so MAXINT - 0 + 1 == -1, which is < 0.
             if (count < 0 || startIndex - count + 1 < 0) {
-                throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_Count"));
+                ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_Count);
             }
 
             return EqualityComparer<T>.Default.LastIndexOf(array, value, startIndex, count);            
@@ -1546,7 +1555,7 @@ namespace System {
         [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
         public static void Reverse(Array array) {
             if (array==null)
-                throw new ArgumentNullException("array");
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
             Contract.EndContractBlock();
             Reverse(array, array.GetLowerBound(0), array.Length);
         }
@@ -1561,14 +1570,17 @@ namespace System {
         [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
         public static void Reverse(Array array, int index, int length) {
             if (array==null) 
-                throw new ArgumentNullException("array");
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
             int lowerBound = array.GetLowerBound(0);
-            if (index < lowerBound || length < 0)
-                throw new ArgumentOutOfRangeException((index<0 ? "index" : "length"), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
+            if (index < lowerBound)
+                ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException();
+            if (length < 0)
+                ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.length, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
+
             if (array.Length - (index - lowerBound) < length)
-                throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen"));
+                ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidOffLen);
             if (array.Rank != 1)
-                throw new RankException(Environment.GetResourceString("Rank_MultiDimNotSupported"));
+                ThrowHelper.ThrowRankException(ExceptionResource.Rank_MultiDimNotSupported);
             Contract.EndContractBlock();
 
             bool r = TrySZReverse(array, index, length);
@@ -1610,7 +1622,7 @@ namespace System {
         [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
         public static void Sort(Array array) {
             if (array==null)
-                throw new ArgumentNullException("array");
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
             Contract.EndContractBlock();
             Sort(array, null, array.GetLowerBound(0), array.Length, null);
         }
@@ -1624,7 +1636,7 @@ namespace System {
         [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
         public static void Sort(Array keys, Array items) {
             if (keys==null)
-                throw new ArgumentNullException("keys");
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.keys);
             Contract.EndContractBlock();
             Sort(keys, items, keys.GetLowerBound(0), keys.Length, null);
         }
@@ -1658,7 +1670,7 @@ namespace System {
         [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
         public static void Sort(Array array, IComparer comparer) {
             if (array==null)
-                throw new ArgumentNullException("array");
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
             Contract.EndContractBlock();
             Sort(array, null, array.GetLowerBound(0), array.Length, comparer);
         }
@@ -1674,7 +1686,7 @@ namespace System {
         [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
         public static void Sort(Array keys, Array items, IComparer comparer) {
             if (keys==null)
-                throw new ArgumentNullException("keys");
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.keys);
             Contract.EndContractBlock();
             Sort(keys, items, keys.GetLowerBound(0), keys.Length, comparer);
         }
@@ -1702,16 +1714,19 @@ namespace System {
         [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
         public static void Sort(Array keys, Array items, int index, int length, IComparer comparer) {
             if (keys==null)
-                throw new ArgumentNullException("keys");
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.keys);
             if (keys.Rank != 1 || (items != null && items.Rank != 1))
-                throw new RankException(Environment.GetResourceString("Rank_MultiDimNotSupported"));
+                ThrowHelper.ThrowRankException(ExceptionResource.Rank_MultiDimNotSupported);
             int keysLowerBound = keys.GetLowerBound(0);
             if (items != null && keysLowerBound != items.GetLowerBound(0))
-                throw new ArgumentException(Environment.GetResourceString("Arg_LowerBoundsMustMatch"));
-            if (index < keysLowerBound || length < 0)
-                throw new ArgumentOutOfRangeException((length<0 ? "length" : "index"), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
+                ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_LowerBoundsMustMatch);
+            if (index < keysLowerBound)
+                ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException();
+            if (length < 0)
+                ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.length, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
+
             if (keys.Length - (index - keysLowerBound) < length || (items != null && (index - keysLowerBound) > items.Length - length))
-                throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen"));
+                ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidOffLen);
 
             Contract.EndContractBlock();
             
@@ -1745,7 +1760,7 @@ namespace System {
         [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
         public static void Sort<T>(T[] array) {
             if (array==null)
-                throw new ArgumentNullException("array");
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
             Contract.EndContractBlock();
             Sort<T>(array, 0, array.Length, null);
         }
@@ -1753,7 +1768,7 @@ namespace System {
         [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
         public static void Sort<TKey, TValue>(TKey[] keys, TValue[] items) {
             if (keys==null)
-                throw new ArgumentNullException("keys");
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.keys);
             Contract.EndContractBlock();
             Sort<TKey, TValue>(keys, items, 0, keys.Length, null);
         }
@@ -1770,8 +1785,8 @@ namespace System {
 
         [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
         public static void Sort<T>(T[] array, System.Collections.Generic.IComparer<T> comparer) {
-            if (array==null)
-                throw new ArgumentNullException("array");
+            if (array == null)
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
             Contract.EndContractBlock();
             Sort<T>(array, 0, array.Length, comparer);
         }
@@ -1779,7 +1794,7 @@ namespace System {
         [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
         public static void Sort<TKey, TValue>(TKey[] keys, TValue[] items, System.Collections.Generic.IComparer<TKey> comparer) {
             if (keys==null)
-                throw new ArgumentNullException("keys");
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.keys);
             Contract.EndContractBlock();
             Sort<TKey, TValue>(keys, items, 0, keys.Length, comparer);
         }
@@ -1788,11 +1803,13 @@ namespace System {
         [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
         public static void Sort<T>(T[] array, int index, int length, System.Collections.Generic.IComparer<T> comparer) {
             if (array==null)
-                throw new ArgumentNullException("array");
-            if (index < 0 || length < 0)
-                throw new ArgumentOutOfRangeException((length<0 ? "length" : "index"), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
+            if (index < 0)
+                ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException();
+            if (length < 0)
+                ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.length, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
             if (array.Length - index < length)
-                throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen"));
+                ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidOffLen);
             Contract.EndContractBlock();
 
             if (length > 1) {
@@ -1810,11 +1827,13 @@ namespace System {
         [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
         public static void Sort<TKey, TValue>(TKey[] keys, TValue[] items, int index, int length, System.Collections.Generic.IComparer<TKey> comparer) {
             if (keys==null)
-                throw new ArgumentNullException("keys");
-            if (index < 0 || length < 0)
-                throw new ArgumentOutOfRangeException((length<0 ? "length" : "index"), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.keys);
+            if (index < 0)
+                ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException();
+            if (length < 0)
+                ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.length, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
             if (keys.Length - index < length || (items != null && index > items.Length - length))
-                throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen"));
+                ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidOffLen);
             Contract.EndContractBlock();
 
             if (length > 1) {
@@ -1836,11 +1855,11 @@ namespace System {
 
         public static void Sort<T>(T[] array, Comparison<T> comparison) {
             if( array == null) {
-                throw new ArgumentNullException("array");
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
             }
 
             if( comparison == null) {
-                throw new ArgumentNullException("comparison");
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.comparison);
             }
             Contract.EndContractBlock();
 
@@ -1850,11 +1869,11 @@ namespace System {
 
         public static bool TrueForAll<T>(T[] array, Predicate<T> match) {
             if( array == null) {
-                throw new ArgumentNullException("array");
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
             }
 
             if( match == null) {
-                throw new ArgumentNullException("match");
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.match);
             }
             Contract.EndContractBlock();
 
@@ -1950,11 +1969,11 @@ namespace System {
                         }
                         catch (IndexOutOfRangeException)
                         {
-                            throw new ArgumentException(Environment.GetResourceString("Arg_BogusIComparer", comparer));
+                            ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_BogusIComparer, ExceptionArgument.comparer);
                         }
                         catch (Exception e)
                         {
-                            throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_IComparerFailed"), e);
+                            ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_IComparerFailed, e);
                         }
                     }
 
@@ -1976,7 +1995,7 @@ namespace System {
                     }
                     catch (Exception e)
                     {
-                        throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_IComparerFailed"), e);
+                        ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_IComparerFailed, e);
                     }
                     Object x = keys[middle];
                     do
@@ -1990,11 +2009,11 @@ namespace System {
                         }
                         catch (IndexOutOfRangeException)
                         {
-                            throw new ArgumentException(Environment.GetResourceString("Arg_BogusIComparer", comparer));
+                            ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_BogusIComparer, ExceptionArgument.comparer);
                         }
                         catch (Exception e)
                         {
-                            throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_IComparerFailed"), e);
+                            ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_IComparerFailed, e);
                         }
                         Contract.Assert(i >= left && j <= right, "(i>=left && j<=right)  Sort failed - Is your IComparer bogus?");
                         if (i > j) break;
@@ -2047,7 +2066,7 @@ namespace System {
                 }
                 catch (Exception e)
                 {
-                    throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_IComparerFailed"), e);
+                    ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_IComparerFailed, e);
                 }
             }
 
@@ -2269,11 +2288,11 @@ namespace System {
                         }
                         catch (IndexOutOfRangeException)
                         {
-                            throw new ArgumentException(Environment.GetResourceString("Arg_BogusIComparer", comparer));
+                            ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_BogusIComparer, ExceptionArgument.comparer);
                         }
                         catch (Exception e)
                         {
-                            throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_IComparerFailed"), e);
+                            ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_IComparerFailed, e);
                         }
                     }
 
@@ -2292,7 +2311,7 @@ namespace System {
                     }
                     catch (Exception e)
                     {
-                        throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_IComparerFailed"), e);
+                        ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_IComparerFailed, e);
                     }
 
                     Object x = keys.GetValue(middle);
@@ -2307,11 +2326,11 @@ namespace System {
                         }
                         catch (IndexOutOfRangeException)
                         {
-                            throw new ArgumentException(Environment.GetResourceString("Arg_BogusIComparer", comparer));
+                            ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_BogusIComparer, ExceptionArgument.comparer);
                         }
                         catch (Exception e)
                         {
-                            throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_IComparerFailed"), e);
+                            ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_IComparerFailed, e);
                         }
                         Contract.Assert(i >= left && j <= right, "(i>=left && j<=right)  Sort failed - Is your IComparer bogus?");
                         if (i > j) break;
@@ -2364,7 +2383,7 @@ namespace System {
                 }
                 catch (Exception e)
                 {
-                    throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_IComparerFailed"), e);
+                    ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_IComparerFailed, e);
                 }
             }
 
@@ -2532,8 +2551,8 @@ namespace System {
     
             public Object Current {
                 get {
-                    if (_index < 0) throw new InvalidOperationException(Environment.GetResourceString(ResId.InvalidOperation_EnumNotStarted));
-                    if (_index >= _endIndex) throw new InvalidOperationException(Environment.GetResourceString(ResId.InvalidOperation_EnumEnded));
+                    if (_index < 0) ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumNotStarted);
+                    if (_index >= _endIndex) ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumEnded);
                     return _array.GetValue(_index);
                 }
             }
@@ -2610,8 +2629,8 @@ namespace System {
     
             public Object Current {
                 get {
-                    if (index < startIndex) throw new InvalidOperationException(Environment.GetResourceString(ResId.InvalidOperation_EnumNotStarted));
-                    if (_complete) throw new InvalidOperationException(Environment.GetResourceString(ResId.InvalidOperation_EnumEnded));
+                    if (index < startIndex) ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumNotStarted);
+                    if (_complete) ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumEnded);
                     return array.GetValue(_indices);
                 }
             }
@@ -2734,7 +2753,7 @@ namespace System {
 
         void Add<T>(T value) {
             // Not meaningful for arrays.
-            throw new NotSupportedException(Environment.GetResourceString("NotSupported_FixedSizeCollection"));
+            ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_FixedSizeCollection);
         }
 
         [SecuritySafeCritical]
@@ -2752,7 +2771,8 @@ namespace System {
         void Clear<T>() {
             //! Warning: "this" is an array, not an SZArrayHelper. See comments above
             //! or you may introduce a security hole!
-            throw new NotSupportedException(Environment.GetResourceString("NotSupported_ReadOnlyCollection"));                        
+
+            ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_ReadOnlyCollection);                     
         }
 
         [SecuritySafeCritical]
@@ -2765,17 +2785,18 @@ namespace System {
         
         void Insert<T>(int index, T value) {
             // Not meaningful for arrays
-            throw new NotSupportedException(Environment.GetResourceString("NotSupported_FixedSizeCollection"));
+            ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_FixedSizeCollection);
         }
 
         bool Remove<T>(T value) {
             // Not meaningful for arrays
-            throw new NotSupportedException(Environment.GetResourceString("NotSupported_FixedSizeCollection"));
+            ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_FixedSizeCollection);
+            return default(bool);
         }
 
         void RemoveAt<T>(int index) {
             // Not meaningful for arrays
-            throw new NotSupportedException(Environment.GetResourceString("NotSupported_FixedSizeCollection"));
+            ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_FixedSizeCollection);
         }
 
         // This is a normal generic Enumerator for SZ arrays. It doesn't have any of the "this" stuff
@@ -2807,8 +2828,8 @@ namespace System {
     
             public T Current {
                 get {
-                    if (_index < 0) throw new InvalidOperationException(Environment.GetResourceString(ResId.InvalidOperation_EnumNotStarted));
-                    if (_index >= _endIndex) throw new InvalidOperationException(Environment.GetResourceString(ResId.InvalidOperation_EnumEnded));
+                    if (_index < 0) ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumNotStarted);
+                    if (_index >= _endIndex) ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumEnded);
                     return _array[_index];
                 }
             }
index 8c9701d..c6be49f 100644 (file)
@@ -47,6 +47,11 @@ namespace System
         // This can be removed after V2, when we implement other schemes
         // of keeping the JIT-compiler out for generic instantiations.
 
+        // Method marked as NoOptimization as we don't want the JIT to
+        // inline any methods or take any short-circuit paths since the 
+        // instantiation closure process is driven by "fixup" references 
+        // left in the final code stream.
+        [MethodImplAttribute(MethodImplOptions.NoOptimization)]
         static void CommonlyUsedGenericInstantiations()
         {
             // Make absolutely sure we include some of the most common 
@@ -54,10 +59,11 @@ namespace System
             // Note that reference type instantiations are already included
             // automatically for us.
 
-            System.Array.Sort<double>(null);
-            System.Array.Sort<int>(null);
-            System.Array.Sort<IntPtr>(null);
-            
+            // Need to sort non null, len > 1 array or paths will short-circuit
+            Array.Sort<double>(new double[1]);
+            Array.Sort<int>(new int[1]);
+            Array.Sort<IntPtr>(new IntPtr[1]);
+
             new ArraySegment<byte>(new byte[1], 0, 0);
 
             new Dictionary<Char, Object>();
index a021c9d..db1419d 100644 (file)
@@ -47,6 +47,12 @@ namespace System {
                                                     Environment.GetResourceString(GetResourceName(ExceptionResource.ArgumentOutOfRange_Index)));
         }
 
+        internal static void ThrowIndexArgumentOutOfRange_NeedNonNegNumException() {
+            throw new ArgumentOutOfRangeException(
+                        GetArgumentName(ExceptionArgument.index),
+                        Environment.GetResourceString(GetResourceName(ExceptionResource.ArgumentOutOfRange_NeedNonNegNum)));
+        }
+
         internal static void ThrowWrongKeyTypeArgumentException(object key, Type targetType) {
             throw new ArgumentException(Environment.GetResourceString("Arg_WrongType", key, targetType), "key");
         }
@@ -86,10 +92,19 @@ namespace System {
                                                     Environment.GetResourceString(GetResourceName(resource)));
         }
 
+        internal static void ThrowArgumentOutOfRangeException(ExceptionArgument argument, int paramNumber, ExceptionResource resource) {
+            throw new ArgumentOutOfRangeException(GetArgumentName(argument) + "[" + paramNumber.ToString() + "]",
+                                                    Environment.GetResourceString(GetResourceName(resource)));
+        }
+
         internal static void ThrowInvalidOperationException(ExceptionResource resource) {
             throw new InvalidOperationException(Environment.GetResourceString(GetResourceName(resource)));
         }
 
+        internal static void ThrowInvalidOperationException(ExceptionResource resource, Exception e) {
+            throw new InvalidOperationException(Environment.GetResourceString(GetResourceName(resource)), e);
+        }
+
         internal static void ThrowSerializationException(ExceptionResource resource) {
             throw new SerializationException(Environment.GetResourceString(GetResourceName(resource)));
         }
@@ -98,6 +113,10 @@ namespace System {
             throw new System.Security.SecurityException(Environment.GetResourceString(GetResourceName(resource)));
         }
 
+        internal static void ThrowRankException(ExceptionResource resource) {
+            throw new RankException(Environment.GetResourceString(GetResourceName(resource)));
+        }
+
         internal static void ThrowNotSupportedException(ExceptionResource resource) {
             throw new NotSupportedException(Environment.GetResourceString(GetResourceName(resource)));
         }
@@ -178,6 +197,27 @@ namespace System {
         action,
         comparison,
         offset,
+        newSize,
+        elementType,
+        length,
+        length1,
+        length2,
+        length3,
+        lengths,
+        len,
+        lowerBounds,
+        sourceArray,
+        destinationArray,
+        sourceIndex,
+        destinationIndex,
+        indices,
+        index1,
+        index2,
+        index3,
+        other,
+        comparer,
+        endIndex,
+        keys,
 
     }
 
@@ -234,6 +274,21 @@ namespace System {
         Argument_InvalidRegistryOptionsCheck,
         Argument_InvalidRegistryViewCheck,
         InvalidOperation_NullArray,
+        Arg_MustBeType,
+        Arg_NeedAtLeast1Rank,
+        ArgumentOutOfRange_HugeArrayNotSupported,
+        Arg_RanksAndBounds,
+        Arg_RankIndices,
+        Arg_Need1DArray,
+        Arg_Need2DArray,
+        Arg_Need3DArray,
+        NotSupported_FixedSizeCollection,
+        ArgumentException_OtherNotArrayOfCorrectLength,
+        Rank_MultiDimNotSupported,
+        InvalidOperation_IComparerFailed,
+        ArgumentOutOfRange_EndIndexStartIndex,
+        Arg_LowerBoundsMustMatch,
+        Arg_BogusIComparer,
 
     }
 }