Fix ArgumentNullException messages passed as parameter names (#2889)
authorHugh Bellamy <hughbellars@gmail.com>
Tue, 10 May 2016 14:52:05 +0000 (15:52 +0100)
committerJan Kotas <jkotas@microsoft.com>
Tue, 10 May 2016 14:52:05 +0000 (07:52 -0700)
Fixed several ArgumentNullExceptions that throw with the message as the parameter name, leading to potential confusion for developers.

src/mscorlib/src/System/AppDomain.cs
src/mscorlib/src/System/AppDomainManager.cs
src/mscorlib/src/System/Globalization/DateTimeFormatInfo.cs
src/mscorlib/src/System/Reflection/FieldInfo.cs
src/mscorlib/src/System/Runtime/InteropServices/Marshal.cs
src/mscorlib/src/System/Security/Policy/ApplicationTrust.cs
src/mscorlib/src/System/StubHelpers.cs
src/mscorlib/src/System/Text/StringBuilder.cs
src/mscorlib/src/System/Threading/WaitHandle.cs

index d78418d..89d6970 100644 (file)
@@ -3289,7 +3289,7 @@ namespace System {
                                       AppDomainSetup info)
         {
             if (friendlyName == null)
-                throw new ArgumentNullException(Environment.GetResourceString("ArgumentNull_String"));
+                throw new ArgumentNullException("friendlyName", Environment.GetResourceString("ArgumentNull_String"));
 
             Contract.EndContractBlock();
 
index 14a817c..291099e 100644 (file)
@@ -59,7 +59,7 @@ namespace System {
                                                        Evidence securityInfo,
                                                        AppDomainSetup appDomainInfo) {
             if (friendlyName == null)
-                throw new ArgumentNullException(Environment.GetResourceString("ArgumentNull_String"));
+                throw new ArgumentNullException("friendlyName", Environment.GetResourceString("ArgumentNull_String"));
 
             Contract.EndContractBlock();
             // If evidence is provided, we check to make sure that is allowed.
index 9adbd66..d08332f 100644 (file)
@@ -2056,7 +2056,7 @@ namespace System.Globalization {
             {
                 if (patterns[i] == null)
                 {
-                    throw new ArgumentNullException(Environment.GetResourceString("ArgumentNull_ArrayValue"));
+                    throw new ArgumentNullException("patterns[" + i + "]", Environment.GetResourceString("ArgumentNull_ArrayValue"));
                 }
             }
 
index eb35ef6..5247c47 100644 (file)
@@ -36,7 +36,7 @@ namespace System.Reflection
         public static FieldInfo GetFieldFromHandle(RuntimeFieldHandle handle)
         {
             if (handle.IsNullHandle())
-                throw new ArgumentException(Environment.GetResourceString("Argument_InvalidHandle"));
+                throw new ArgumentException(Environment.GetResourceString("Argument_InvalidHandle"), "handle");
                 
             FieldInfo f = RuntimeType.GetFieldInfo(handle.GetRuntimeFieldInfo());
                        
index ea675f8..945c4f7 100644 (file)
@@ -1060,7 +1060,7 @@ namespace System.Runtime.InteropServices
             }
 
             if (rtModule == null)
-                throw new ArgumentNullException(Environment.GetResourceString("Argument_MustBeRuntimeModule"));
+                throw new ArgumentNullException("m", Environment.GetResourceString("Argument_MustBeRuntimeModule"));
 
             return GetHINSTANCE(rtModule.GetNativeHandle());
         }    
index 4b6d8b1..57b216e 100644 (file)
@@ -91,7 +91,7 @@ namespace System.Security.Policy {
             List<StrongName> fullTrustList = new List<StrongName>();
             foreach (StrongName strongName in fullTrustAssemblies) {
                 if (strongName == null) {
-                    throw new ArgumentException(Environment.GetResourceString("Argument_NullFullTrustAssembly"));
+                    throw new ArgumentException(Environment.GetResourceString("Argument_NullFullTrustAssembly"), "fullTrustAssemblies");
                 }
 
                 fullTrustList.Add(new StrongName(strongName.PublicKey, strongName.Name, strongName.Version));
@@ -120,7 +120,7 @@ namespace System.Security.Policy {
             }
             set {
                 if (value == null)
-                    throw new ArgumentNullException(Environment.GetResourceString("Argument_InvalidAppId"));
+                    throw new ArgumentNullException("value", Environment.GetResourceString("Argument_InvalidAppId"));
                 Contract.EndContractBlock();
                 m_appId = value;
             }
index b189fa5..633becd 100644 (file)
@@ -1670,7 +1670,7 @@ namespace  System.StubHelpers {
         {
             if (pHandle == null)
             {
-                throw new ArgumentNullException(Environment.GetResourceString("ArgumentNull_SafeHandle"));
+                throw new ArgumentNullException("pHandle", Environment.GetResourceString("ArgumentNull_SafeHandle"));
             }
             Contract.EndContractBlock();
 
@@ -1686,7 +1686,7 @@ namespace  System.StubHelpers {
         {
             if (pHandle == null)
             {
-                throw new ArgumentNullException(Environment.GetResourceString("ArgumentNull_SafeHandle"));
+                throw new ArgumentNullException("pHandle", Environment.GetResourceString("ArgumentNull_SafeHandle"));
             }
             Contract.EndContractBlock();
 
index 809b515..3c071b3 100644 (file)
@@ -1108,7 +1108,7 @@ namespace System.Text {
                 {
                     return this;
                 }
-                throw new ArgumentNullException(Environment.GetResourceString("ArgumentNull_String"));
+                throw new ArgumentNullException("value", Environment.GetResourceString("ArgumentNull_String"));
             }
 
             //Range check the array.
index 30d6872..7703a49 100644 (file)
@@ -281,7 +281,7 @@ namespace System.Threading
         {
             if (waitHandles == null)
             {
-                throw new ArgumentNullException(Environment.GetResourceString("ArgumentNull_Waithandles"));
+                throw new ArgumentNullException("waitHandles", Environment.GetResourceString("ArgumentNull_Waithandles"));
             }
             if(waitHandles.Length == 0)
             {
@@ -297,7 +297,7 @@ namespace System.Threading
 #if FEATURE_CORECLR
                 throw new ArgumentException(Environment.GetResourceString("Argument_EmptyWaithandleArray"));
 #else
-                throw new ArgumentNullException(Environment.GetResourceString("Argument_EmptyWaithandleArray"));
+                throw new ArgumentNullException("waitHandles", Environment.GetResourceString("Argument_EmptyWaithandleArray"));
 #endif
             }
             if (waitHandles.Length > MAX_WAITHANDLES)
@@ -315,7 +315,7 @@ namespace System.Threading
                 WaitHandle waitHandle = waitHandles[i];
 
                 if (waitHandle == null)
-                    throw new ArgumentNullException(Environment.GetResourceString("ArgumentNull_ArrayElement"));
+                    throw new ArgumentNullException("waitHandles[" + i + "]", Environment.GetResourceString("ArgumentNull_ArrayElement"));
 
 #if FEATURE_REMOTING        
                 if (RemotingServices.IsTransparentProxy(waitHandle))
@@ -394,7 +394,7 @@ namespace System.Threading
         {
             if (waitHandles==null)
             {
-                throw new ArgumentNullException(Environment.GetResourceString("ArgumentNull_Waithandles"));
+                throw new ArgumentNullException("waitHandles", Environment.GetResourceString("ArgumentNull_Waithandles"));
             }
             if(waitHandles.Length == 0)
             {
@@ -415,7 +415,7 @@ namespace System.Threading
                 WaitHandle waitHandle = waitHandles[i];
 
                 if (waitHandle == null)
-                    throw new ArgumentNullException(Environment.GetResourceString("ArgumentNull_ArrayElement"));
+                    throw new ArgumentNullException("waitHandles[" + i + "]", Environment.GetResourceString("ArgumentNull_ArrayElement"));
 
 #if FEATURE_REMOTING        
                 if (RemotingServices.IsTransparentProxy(waitHandle))