diff --git a/eng/CodeAnalysis.ruleset b/eng/CodeAnalysis.ruleset
index cf97025667a2bd..408bc1b422fe31 100644
--- a/eng/CodeAnalysis.ruleset
+++ b/eng/CodeAnalysis.ruleset
@@ -106,7 +106,7 @@
-
+
diff --git a/src/coreclr/src/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComActivator.cs b/src/coreclr/src/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComActivator.cs
index 8f7d8ecd550be9..a5232b25091025 100644
--- a/src/coreclr/src/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComActivator.cs
+++ b/src/coreclr/src/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComActivator.cs
@@ -124,7 +124,7 @@ public static object GetClassFactoryForType(ComActivationContext cxt)
if (!Path.IsPathRooted(cxt.AssemblyPath))
{
- throw new ArgumentException();
+ throw new ArgumentException(null, nameof(cxt));
}
Type classType = FindClassType(cxt.ClassId, cxt.AssemblyPath, cxt.AssemblyName, cxt.TypeName);
@@ -156,7 +156,7 @@ public static void ClassRegistrationScenarioForType(ComActivationContext cxt, bo
if (!Path.IsPathRooted(cxt.AssemblyPath))
{
- throw new ArgumentException();
+ throw new ArgumentException(null, nameof(cxt));
}
Type classType = FindClassType(cxt.ClassId, cxt.AssemblyPath, cxt.AssemblyName, cxt.TypeName);
@@ -288,7 +288,7 @@ public static unsafe int RegisterClassForTypeInternal(ComActivationContextIntern
if (cxtInt.InterfaceId != Guid.Empty
|| cxtInt.ClassFactoryDest != IntPtr.Zero)
{
- throw new ArgumentException();
+ throw new ArgumentException(null, nameof(pCxtInt));
}
try
@@ -328,7 +328,7 @@ public static unsafe int UnregisterClassForTypeInternal(ComActivationContextInte
if (cxtInt.InterfaceId != Guid.Empty
|| cxtInt.ClassFactoryDest != IntPtr.Zero)
{
- throw new ArgumentException();
+ throw new ArgumentException(null, nameof(pCxtInt));
}
try
diff --git a/src/coreclr/src/System.Private.CoreLib/src/System/GC.cs b/src/coreclr/src/System.Private.CoreLib/src/System/GC.cs
index fc8a9650f63b7e..e3e1b54373fa5e 100644
--- a/src/coreclr/src/System.Private.CoreLib/src/System/GC.cs
+++ b/src/coreclr/src/System.Private.CoreLib/src/System/GC.cs
@@ -135,7 +135,7 @@ public static void AddMemoryPressure(long bytesAllocated)
if ((4 == IntPtr.Size) && (bytesAllocated > int.MaxValue))
{
- throw new ArgumentOutOfRangeException("pressure",
+ throw new ArgumentOutOfRangeException(nameof(bytesAllocated),
SR.ArgumentOutOfRange_MustBeNonNegInt32);
}
diff --git a/src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/ComWrappers.cs b/src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/ComWrappers.cs
index 0229ac9c0dbc55..d72d783389f020 100644
--- a/src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/ComWrappers.cs
+++ b/src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/ComWrappers.cs
@@ -121,7 +121,7 @@ public IntPtr GetOrCreateComInterfaceForObject(object instance, CreateComInterfa
{
IntPtr ptr;
if (!TryGetOrCreateComInterfaceForObjectInternal(this, instance, flags, out ptr))
- throw new ArgumentException();
+ throw new ArgumentException(null, nameof(instance));
return ptr;
}
@@ -187,7 +187,7 @@ public object GetOrCreateObjectForComInstance(IntPtr externalComObject, CreateOb
{
object? obj;
if (!TryGetOrCreateObjectForComInstanceInternal(this, externalComObject, flags, null, out obj))
- throw new ArgumentNullException();
+ throw new ArgumentNullException(nameof(externalComObject));
return obj!;
}
@@ -230,7 +230,7 @@ public object GetOrRegisterObjectForComInstance(IntPtr externalComObject, Create
object? obj;
if (!TryGetOrCreateObjectForComInstanceInternal(this, externalComObject, flags, wrapper, out obj))
- throw new ArgumentNullException();
+ throw new ArgumentNullException(nameof(externalComObject));
return obj!;
}
@@ -319,4 +319,4 @@ internal static int CallICustomQueryInterface(object customQueryInterfaceMaybe,
return (int)customQueryInterface.GetInterface(ref iid, out ppObject);
}
}
-}
\ No newline at end of file
+}
diff --git a/src/coreclr/src/System.Private.CoreLib/src/System/RuntimeType.CoreCLR.cs b/src/coreclr/src/System.Private.CoreLib/src/System/RuntimeType.CoreCLR.cs
index 93cfd86bc167b1..174a8014aaf63f 100644
--- a/src/coreclr/src/System.Private.CoreLib/src/System/RuntimeType.CoreCLR.cs
+++ b/src/coreclr/src/System.Private.CoreLib/src/System/RuntimeType.CoreCLR.cs
@@ -1896,7 +1896,7 @@ private static void ThrowIfTypeNeverValidGenericArgument(RuntimeType type)
internal static void SanityCheckGenericArguments(RuntimeType[] genericArguments, RuntimeType[] genericParamters)
{
if (genericArguments == null)
- throw new ArgumentNullException();
+ throw new ArgumentNullException(nameof(genericArguments));
for (int i = 0; i < genericArguments.Length; i++)
{
@@ -2752,7 +2752,7 @@ public override InterfaceMapping GetInterfaceMap(Type ifaceType)
protected override PropertyInfo? GetPropertyImpl(
string name, BindingFlags bindingAttr, Binder? binder, Type? returnType, Type[]? types, ParameterModifier[]? modifiers)
{
- if (name == null) throw new ArgumentNullException();
+ if (name == null) throw new ArgumentNullException(nameof(name));
ListBuilder candidates = GetPropertyCandidates(name, bindingAttr, types, false);
@@ -2788,7 +2788,7 @@ public override InterfaceMapping GetInterfaceMap(Type ifaceType)
public override EventInfo? GetEvent(string name, BindingFlags bindingAttr)
{
- if (name is null) throw new ArgumentNullException();
+ if (name is null) throw new ArgumentNullException(nameof(name));
FilterHelper(bindingAttr, ref name, out _, out MemberListType listType);
@@ -2814,7 +2814,7 @@ public override InterfaceMapping GetInterfaceMap(Type ifaceType)
public override FieldInfo? GetField(string name, BindingFlags bindingAttr)
{
- if (name is null) throw new ArgumentNullException();
+ if (name is null) throw new ArgumentNullException(nameof(name));
FilterHelper(bindingAttr, ref name, out _, out MemberListType listType);
@@ -2851,7 +2851,7 @@ public override InterfaceMapping GetInterfaceMap(Type ifaceType)
public override Type? GetInterface(string fullname, bool ignoreCase)
{
- if (fullname is null) throw new ArgumentNullException();
+ if (fullname is null) throw new ArgumentNullException(nameof(fullname));
BindingFlags bindingAttr = BindingFlags.Public | BindingFlags.NonPublic;
@@ -2885,7 +2885,7 @@ public override InterfaceMapping GetInterfaceMap(Type ifaceType)
public override Type? GetNestedType(string fullname, BindingFlags bindingAttr)
{
- if (fullname is null) throw new ArgumentNullException();
+ if (fullname is null) throw new ArgumentNullException(nameof(fullname));
bindingAttr &= ~BindingFlags.Static;
string name, ns;
@@ -2913,7 +2913,7 @@ public override InterfaceMapping GetInterfaceMap(Type ifaceType)
public override MemberInfo[] GetMember(string name, MemberTypes type, BindingFlags bindingAttr)
{
- if (name is null) throw new ArgumentNullException();
+ if (name is null) throw new ArgumentNullException(nameof(name));
ListBuilder methods = default;
ListBuilder constructors = default;
diff --git a/src/coreclr/src/System.Private.CoreLib/src/System/Threading/ThreadPool.CoreCLR.cs b/src/coreclr/src/System.Private.CoreLib/src/System/Threading/ThreadPool.CoreCLR.cs
index c2d72e3915cae7..712e29fcf99457 100644
--- a/src/coreclr/src/System.Private.CoreLib/src/System/Threading/ThreadPool.CoreCLR.cs
+++ b/src/coreclr/src/System.Private.CoreLib/src/System/Threading/ThreadPool.CoreCLR.cs
@@ -287,7 +287,7 @@ bool compressStack
}
else
{
- throw new ArgumentNullException(nameof(WaitOrTimerCallback));
+ throw new ArgumentNullException(nameof(callBack));
}
return registeredWaitHandle;
}
diff --git a/src/libraries/Common/src/System/Threading/Tasks/TaskToApm.cs b/src/libraries/Common/src/System/Threading/Tasks/TaskToApm.cs
index ecd9f27ecb8dd8..96b41501f3407d 100644
--- a/src/libraries/Common/src/System/Threading/Tasks/TaskToApm.cs
+++ b/src/libraries/Common/src/System/Threading/Tasks/TaskToApm.cs
@@ -43,7 +43,7 @@ public static void End(IAsyncResult asyncResult)
return;
}
- throw new ArgumentNullException();
+ throw new ArgumentNullException(nameof(asyncResult));
}
/// Processes an IAsyncResult returned by Begin.
@@ -55,7 +55,7 @@ public static TResult End(IAsyncResult asyncResult)
return task.GetAwaiter().GetResult();
}
- throw new ArgumentNullException();
+ throw new ArgumentNullException(nameof(asyncResult));
}
/// Provides a simple IAsyncResult that wraps a Task.
diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/DiagnosticCounter.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/DiagnosticCounter.cs
index 577e9f193f8c11..c6081e15bc5359 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/DiagnosticCounter.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/DiagnosticCounter.cs
@@ -32,12 +32,12 @@ internal DiagnosticCounter(string name, EventSource eventSource)
{
if (name == null)
{
- throw new ArgumentNullException(nameof(Name));
+ throw new ArgumentNullException(nameof(name));
}
if (eventSource == null)
{
- throw new ArgumentNullException(nameof(EventSource));
+ throw new ArgumentNullException(nameof(eventSource));
}
Name = name;
diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/EventSourceActivity.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/EventSourceActivity.cs
index b68bac3e546479..3a9d3e5428e1d1 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/EventSourceActivity.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/EventSourceActivity.cs
@@ -262,7 +262,7 @@ private void Write(EventSource eventSource, string? eventName, ref EventSourc
if (this.state != State.Started)
throw new InvalidOperationException(); // Write after stop.
if (eventName == null)
- throw new ArgumentNullException();
+ throw new ArgumentNullException(nameof(eventName));
eventSource.Write(eventName, ref options, ref this.activityId, ref s_empty, ref data);
}
diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/TraceLoggingEventSource.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/TraceLoggingEventSource.cs
index aa13daa55b4d1d..37ffeaa39cb8ec 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/TraceLoggingEventSource.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/TraceLoggingEventSource.cs
@@ -813,7 +813,7 @@ private static int AddValueToMetaData(List metaData, string value)
{
if (!(i + 1 < value.Length))
{
- throw new ArgumentException(SR.EventSource_EvenHexDigits, "traits");
+ throw new ArgumentException(SR.EventSource_EvenHexDigits, nameof(value));
}
metaData.Add((byte)(HexDigit(value[i]) * 16 + HexDigit(value[i + 1])));
i++;
@@ -826,7 +826,7 @@ private static int AddValueToMetaData(List metaData, string value)
}
else
{
- throw new ArgumentException(SR.Format(SR.EventSource_IllegalValue, value), "traits");
+ throw new ArgumentException(SR.Format(SR.EventSource_IllegalValue, value), nameof(value));
}
return metaData.Count - startPos;
@@ -850,7 +850,7 @@ private static int HexDigit(char c)
return c - 'A' + 10;
}
- throw new ArgumentException(SR.Format(SR.EventSource_BadHexDigit, c), "traits");
+ throw new ArgumentException(SR.Format(SR.EventSource_BadHexDigit, c), nameof(c));
}
private NameInfo? UpdateDescriptor(
diff --git a/src/libraries/System.Private.CoreLib/src/System/IO/BinaryWriter.cs b/src/libraries/System.Private.CoreLib/src/System/IO/BinaryWriter.cs
index fde451656a5dee..d45ad137c4c34d 100644
--- a/src/libraries/System.Private.CoreLib/src/System/IO/BinaryWriter.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/IO/BinaryWriter.cs
@@ -394,7 +394,7 @@ public virtual unsafe void Write(string value)
{
if (charStart < 0 || charCount < 0 || charStart > value.Length - charCount)
{
- throw new ArgumentOutOfRangeException(nameof(charCount));
+ throw new ArgumentOutOfRangeException(nameof(value));
}
fixed (char* pChars = value)
{
diff --git a/src/libraries/System.Private.CoreLib/src/System/IO/UnmanagedMemoryStream.cs b/src/libraries/System.Private.CoreLib/src/System/IO/UnmanagedMemoryStream.cs
index ecdb454203bf4e..21541fc26066fb 100644
--- a/src/libraries/System.Private.CoreLib/src/System/IO/UnmanagedMemoryStream.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/IO/UnmanagedMemoryStream.cs
@@ -415,7 +415,7 @@ public unsafe byte* PositionPointer
throw new IOException(SR.IO_SeekBeforeBegin);
long newPosition = (long)value - (long)_mem;
if (newPosition < 0)
- throw new ArgumentOutOfRangeException("offset", SR.ArgumentOutOfRange_UnmanagedMemStreamLength);
+ throw new ArgumentOutOfRangeException(nameof(value), SR.ArgumentOutOfRange_UnmanagedMemStreamLength);
Interlocked.Exchange(ref _position, newPosition);
}
diff --git a/src/libraries/System.Private.CoreLib/src/System/Reflection/AssemblyNameFormatter.cs b/src/libraries/System.Private.CoreLib/src/System/Reflection/AssemblyNameFormatter.cs
index 09585f8d58f197..fa1c37873ee6a7 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Reflection/AssemblyNameFormatter.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/AssemblyNameFormatter.cs
@@ -63,7 +63,7 @@ public static string ComputeDisplayName(string? name, Version? version, string?
if (pkt != null)
{
if (pkt.Length > PUBLIC_KEY_TOKEN_LEN)
- throw new ArgumentException();
+ throw new ArgumentException(null, nameof(pkt));
sb.Append(", PublicKeyToken=");
if (pkt.Length == 0)
diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.Windows.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.Windows.cs
index 9889030d88260f..1fc19a90830a22 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.Windows.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.Windows.cs
@@ -97,7 +97,7 @@ internal static unsafe int GetAnsiStringByteCount(ReadOnlySpan chars)
byteLength = Interop.Kernel32.WideCharToMultiByte(
Interop.Kernel32.CP_ACP, Interop.Kernel32.WC_NO_BEST_FIT_CHARS, pChars, chars.Length, null, 0, IntPtr.Zero, IntPtr.Zero);
if (byteLength <= 0)
- throw new ArgumentException();
+ throw new ArgumentException(null, nameof(chars));
}
}
@@ -121,7 +121,7 @@ internal static unsafe void GetAnsiStringBytes(ReadOnlySpan chars, Span (uint)m_MaxCapacity)
{
- throw new ArgumentOutOfRangeException(nameof(Capacity), SR.ArgumentOutOfRange_Capacity);
+ throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_Capacity);
}
while (count > 0)
@@ -1144,7 +1144,9 @@ public StringBuilder Remove(int startIndex, int length)
return this;
}
+#pragma warning disable CA1830 // Prefer strongly-typed Append and Insert method overloads on StringBuilder.
public StringBuilder Append(bool value) => Append(value.ToString());
+#pragma warning restore CA1830 // Prefer strongly-typed Append and Insert method overloads on StringBuilder.
public StringBuilder Append(char value)
{
@@ -2401,7 +2403,7 @@ private void ExpandByABlock(int minBlockCharCount)
if ((minBlockCharCount + Length) > m_MaxCapacity || minBlockCharCount + Length < minBlockCharCount)
{
- throw new ArgumentOutOfRangeException("requiredLength", SR.ArgumentOutOfRange_SmallCapacity);
+ throw new ArgumentOutOfRangeException(nameof(minBlockCharCount), SR.ArgumentOutOfRange_SmallCapacity);
}
// - We always need to make the new chunk at least as big as was requested (`minBlockCharCount`).
@@ -2490,7 +2492,7 @@ private void MakeRoom(int index, int count, out StringBuilder chunk, out int ind
if (count + Length > m_MaxCapacity || count + Length < count)
{
- throw new ArgumentOutOfRangeException("requiredLength", SR.ArgumentOutOfRange_SmallCapacity);
+ throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_SmallCapacity);
}
chunk = this;
diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/Thread.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/Thread.cs
index 8bdf89070a9adc..9abd9ac2aa98a9 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Threading/Thread.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Threading/Thread.cs
@@ -243,7 +243,7 @@ public bool TrySetApartmentState(ApartmentState state)
break;
default:
- throw new ArgumentOutOfRangeException(SR.ArgumentOutOfRange_Enum, nameof(state));
+ throw new ArgumentOutOfRangeException(nameof(state), SR.ArgumentOutOfRange_Enum);
}
return TrySetApartmentStateUnchecked(state);
diff --git a/src/libraries/System.Reflection.Extensions/tests/RuntimeReflectionExtensionTests.cs b/src/libraries/System.Reflection.Extensions/tests/RuntimeReflectionExtensionTests.cs
index f3ca59bbca6871..e5d7fedd7b5355 100644
--- a/src/libraries/System.Reflection.Extensions/tests/RuntimeReflectionExtensionTests.cs
+++ b/src/libraries/System.Reflection.Extensions/tests/RuntimeReflectionExtensionTests.cs
@@ -165,7 +165,7 @@ public void GetRuntimeEvent()
});
- Assert.Throws(null, () =>
+ Assert.Throws("name", () =>
{
typeof(RuntimeReflectionExtensionsTests).GetRuntimeEvent(null);
});
@@ -250,7 +250,7 @@ public void GetRuntimeField()
});
- Assert.Throws(null, () =>
+ Assert.Throws("name", () =>
{
typeof(RuntimeReflectionExtensionsTests).GetRuntimeField(null);
});
diff --git a/src/libraries/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/ComAwareEventInfoTests.cs b/src/libraries/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/ComAwareEventInfoTests.cs
index 49d915e7db76d3..6748d0ad226495 100644
--- a/src/libraries/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/ComAwareEventInfoTests.cs
+++ b/src/libraries/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/ComAwareEventInfoTests.cs
@@ -40,7 +40,7 @@ public void Ctor_NullType_ThrowsNullReferenceException()
[Fact]
public void Ctor_NullEventName_ThrowsArgumentNullException()
{
- AssertExtensions.Throws(null, () => new ComAwareEventInfo(typeof(NonComObject), null));
+ AssertExtensions.Throws("name", () => new ComAwareEventInfo(typeof(NonComObject), null));
}
[Fact]
diff --git a/src/libraries/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/Marshal/OffsetOfTests.cs b/src/libraries/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/Marshal/OffsetOfTests.cs
index fff08985672610..950f55ad0e1406 100644
--- a/src/libraries/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/Marshal/OffsetOfTests.cs
+++ b/src/libraries/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/Marshal/OffsetOfTests.cs
@@ -186,8 +186,8 @@ public void OffsetOf_NullType_ThrowsArgumentNullException()
[Fact]
public void OffsetOf_NullFieldName_ThrowsArgumentNullException()
{
- AssertExtensions.Throws(null, () => Marshal.OffsetOf(new object().GetType(), null));
- AssertExtensions.Throws(null, () => Marshal.OffsetOf