From 29af121b4fe15a79daa9623cb9a0831286d7bd9d Mon Sep 17 00:00:00 2001 From: Hugh Bellamy Date: Tue, 10 May 2016 15:52:05 +0100 Subject: [PATCH] Fix ArgumentNullException messages passed as parameter names (dotnet/coreclr#2889) Fixed several ArgumentNullExceptions that throw with the message as the parameter name, leading to potential confusion for developers. Commit migrated from https://github.com/dotnet/coreclr/commit/ad2485b93ce14437c0dc8b4fb69b0a54177fe09f --- src/coreclr/src/mscorlib/src/System/AppDomain.cs | 2 +- src/coreclr/src/mscorlib/src/System/AppDomainManager.cs | 2 +- .../mscorlib/src/System/Globalization/DateTimeFormatInfo.cs | 2 +- src/coreclr/src/mscorlib/src/System/Reflection/FieldInfo.cs | 2 +- .../src/mscorlib/src/System/Runtime/InteropServices/Marshal.cs | 2 +- .../mscorlib/src/System/Security/Policy/ApplicationTrust.cs | 4 ++-- src/coreclr/src/mscorlib/src/System/StubHelpers.cs | 4 ++-- src/coreclr/src/mscorlib/src/System/Text/StringBuilder.cs | 2 +- src/coreclr/src/mscorlib/src/System/Threading/WaitHandle.cs | 10 +++++----- 9 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/coreclr/src/mscorlib/src/System/AppDomain.cs b/src/coreclr/src/mscorlib/src/System/AppDomain.cs index d78418d..89d6970 100644 --- a/src/coreclr/src/mscorlib/src/System/AppDomain.cs +++ b/src/coreclr/src/mscorlib/src/System/AppDomain.cs @@ -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(); diff --git a/src/coreclr/src/mscorlib/src/System/AppDomainManager.cs b/src/coreclr/src/mscorlib/src/System/AppDomainManager.cs index 14a817c..291099e 100644 --- a/src/coreclr/src/mscorlib/src/System/AppDomainManager.cs +++ b/src/coreclr/src/mscorlib/src/System/AppDomainManager.cs @@ -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. diff --git a/src/coreclr/src/mscorlib/src/System/Globalization/DateTimeFormatInfo.cs b/src/coreclr/src/mscorlib/src/System/Globalization/DateTimeFormatInfo.cs index 9adbd66..d08332f 100644 --- a/src/coreclr/src/mscorlib/src/System/Globalization/DateTimeFormatInfo.cs +++ b/src/coreclr/src/mscorlib/src/System/Globalization/DateTimeFormatInfo.cs @@ -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")); } } diff --git a/src/coreclr/src/mscorlib/src/System/Reflection/FieldInfo.cs b/src/coreclr/src/mscorlib/src/System/Reflection/FieldInfo.cs index eb35ef6..5247c47 100644 --- a/src/coreclr/src/mscorlib/src/System/Reflection/FieldInfo.cs +++ b/src/coreclr/src/mscorlib/src/System/Reflection/FieldInfo.cs @@ -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()); diff --git a/src/coreclr/src/mscorlib/src/System/Runtime/InteropServices/Marshal.cs b/src/coreclr/src/mscorlib/src/System/Runtime/InteropServices/Marshal.cs index ea675f8..945c4f7 100644 --- a/src/coreclr/src/mscorlib/src/System/Runtime/InteropServices/Marshal.cs +++ b/src/coreclr/src/mscorlib/src/System/Runtime/InteropServices/Marshal.cs @@ -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()); } diff --git a/src/coreclr/src/mscorlib/src/System/Security/Policy/ApplicationTrust.cs b/src/coreclr/src/mscorlib/src/System/Security/Policy/ApplicationTrust.cs index 4b6d8b1..57b216e 100644 --- a/src/coreclr/src/mscorlib/src/System/Security/Policy/ApplicationTrust.cs +++ b/src/coreclr/src/mscorlib/src/System/Security/Policy/ApplicationTrust.cs @@ -91,7 +91,7 @@ namespace System.Security.Policy { List fullTrustList = new List(); 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; } diff --git a/src/coreclr/src/mscorlib/src/System/StubHelpers.cs b/src/coreclr/src/mscorlib/src/System/StubHelpers.cs index b189fa5..633becd 100644 --- a/src/coreclr/src/mscorlib/src/System/StubHelpers.cs +++ b/src/coreclr/src/mscorlib/src/System/StubHelpers.cs @@ -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(); diff --git a/src/coreclr/src/mscorlib/src/System/Text/StringBuilder.cs b/src/coreclr/src/mscorlib/src/System/Text/StringBuilder.cs index 809b515..3c071b3 100644 --- a/src/coreclr/src/mscorlib/src/System/Text/StringBuilder.cs +++ b/src/coreclr/src/mscorlib/src/System/Text/StringBuilder.cs @@ -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. diff --git a/src/coreclr/src/mscorlib/src/System/Threading/WaitHandle.cs b/src/coreclr/src/mscorlib/src/System/Threading/WaitHandle.cs index 30d6872..7703a49 100644 --- a/src/coreclr/src/mscorlib/src/System/Threading/WaitHandle.cs +++ b/src/coreclr/src/mscorlib/src/System/Threading/WaitHandle.cs @@ -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)) -- 2.7.4