diff --git a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimRegisterCimIndication.cs b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimRegisterCimIndication.cs
index c08fa0c44ea..24b9332bde5 100644
--- a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimRegisterCimIndication.cs
+++ b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimRegisterCimIndication.cs
@@ -149,8 +149,10 @@ public void RegisterCimIndication(
uint operationTimeout)
{
DebugHelper.WriteLogEx("queryDialect = '{0}'; queryExpression = '{1}'", 0, queryDialect, queryExpression);
-
- ArgumentNullException.ThrowIfNull(cimSession, string.Format(CultureInfo.CurrentUICulture, CimCmdletStrings.NullArgument, nameof(cimSession)));
+ if (cimSession == null)
+ {
+ throw new ArgumentNullException(string.Format(CultureInfo.CurrentUICulture, CimCmdletStrings.NullArgument, nameof(cimSession)));
+ }
this.TargetComputerName = cimSession.ComputerName;
CimSessionProxy proxy = CreateSessionProxy(cimSession, operationTimeout);
diff --git a/src/Microsoft.Management.Infrastructure.CimCmdlets/Utils.cs b/src/Microsoft.Management.Infrastructure.CimCmdlets/Utils.cs
index adcab254231..0cb0cfa7cb1 100644
--- a/src/Microsoft.Management.Infrastructure.CimCmdlets/Utils.cs
+++ b/src/Microsoft.Management.Infrastructure.CimCmdlets/Utils.cs
@@ -361,7 +361,10 @@ internal static class ValidationHelper
///
public static void ValidateNoNullArgument(object obj, string argumentName)
{
- ArgumentNullException.ThrowIfNull(obj, argumentName);
+ if (obj == null)
+ {
+ throw new ArgumentNullException(argumentName);
+ }
}
///
diff --git a/src/Microsoft.Management.UI.Internal/ManagementList/Common/WpfHelp.cs b/src/Microsoft.Management.UI.Internal/ManagementList/Common/WpfHelp.cs
index 4bc9ebef28d..b0839c6ccd2 100644
--- a/src/Microsoft.Management.UI.Internal/ManagementList/Common/WpfHelp.cs
+++ b/src/Microsoft.Management.UI.Internal/ManagementList/Common/WpfHelp.cs
@@ -214,7 +214,10 @@ public static void AddChild(FrameworkElement parent, FrameworkElement element)
{
ArgumentNullException.ThrowIfNull(element);
- ArgumentNullException.ThrowIfNull(parent, nameof(element));
+ if (parent == null)
+ {
+ throw new ArgumentNullException("element");
+ }
ContentControl parentContentControl = parent as ContentControl;
@@ -367,7 +370,10 @@ public static T FindVisualAncestorData(this DependencyObject obj)
/// The specified value is a null reference.
public static T FindVisualAncestor(this DependencyObject @object) where T : class
{
- ArgumentNullException.ThrowIfNull(@object, nameof(@object));
+ if (@object == null)
+ {
+ throw new ArgumentNullException("object");
+ }
DependencyObject parent = VisualTreeHelper.GetParent(@object);
diff --git a/src/Microsoft.Management.UI.Internal/ManagementList/ManagementList/DefaultStringConverter.cs b/src/Microsoft.Management.UI.Internal/ManagementList/ManagementList/DefaultStringConverter.cs
index 2d590904097..cf85d79ae36 100644
--- a/src/Microsoft.Management.UI.Internal/ManagementList/ManagementList/DefaultStringConverter.cs
+++ b/src/Microsoft.Management.UI.Internal/ManagementList/ManagementList/DefaultStringConverter.cs
@@ -62,9 +62,7 @@ public string DefaultValue
///
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
- ArgumentNullException.ThrowIfNull(values);
-
- if (values.Length != 1)
+ if (values == null || values.Length != 1)
{
throw new ArgumentNullException("values");
}
diff --git a/src/Microsoft.Management.UI.Internal/ShowCommand/ViewModel/AllModulesViewModel.cs b/src/Microsoft.Management.UI.Internal/ShowCommand/ViewModel/AllModulesViewModel.cs
index 04fc95e4223..8bc9e024022 100644
--- a/src/Microsoft.Management.UI.Internal/ShowCommand/ViewModel/AllModulesViewModel.cs
+++ b/src/Microsoft.Management.UI.Internal/ShowCommand/ViewModel/AllModulesViewModel.cs
@@ -79,9 +79,7 @@ public class AllModulesViewModel : INotifyPropertyChanged
/// Commands to show.
public AllModulesViewModel(Dictionary importedModules, IEnumerable commands)
{
- ArgumentNullException.ThrowIfNull(commands);
-
- if (!commands.GetEnumerator().MoveNext())
+ if (commands == null || !commands.GetEnumerator().MoveNext())
{
throw new ArgumentNullException("commands");
}
diff --git a/src/Microsoft.PowerShell.Commands.Management/cimSupport/cmdletization/SessionBasedWrapper.cs b/src/Microsoft.PowerShell.Commands.Management/cimSupport/cmdletization/SessionBasedWrapper.cs
index 8da4d7f4c78..58a1fbb4c2d 100644
--- a/src/Microsoft.PowerShell.Commands.Management/cimSupport/cmdletization/SessionBasedWrapper.cs
+++ b/src/Microsoft.PowerShell.Commands.Management/cimSupport/cmdletization/SessionBasedWrapper.cs
@@ -82,8 +82,7 @@ protected TSession[] Session
set
{
- ArgumentNullException.ThrowIfNull(value);
- _session = value;
+ _session = value ?? throw new ArgumentNullException(nameof(value));
_sessionWasSpecified = true;
}
}
diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/TestConnectionCommand.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/TestConnectionCommand.cs
index e11be68156a..e6b33142457 100644
--- a/src/Microsoft.PowerShell.Commands.Management/commands/management/TestConnectionCommand.cs
+++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/TestConnectionCommand.cs
@@ -575,12 +575,10 @@ private void ProcessMTUSize(string targetNameOrAddress)
}
else
{
- ArgumentNullException.ThrowIfNull(replyResult);
-
WriteObject(new PingMtuStatus(
Source,
resolvedTargetName,
- replyResult,
+ replyResult ?? throw new ArgumentNullException(nameof(replyResult)),
CurrentMTUSize));
}
}
diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/InvokeRestMethodCommand.Common.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/InvokeRestMethodCommand.Common.cs
index a27e4e70008..9864deb7772 100644
--- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/InvokeRestMethodCommand.Common.cs
+++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/InvokeRestMethodCommand.Common.cs
@@ -163,7 +163,7 @@ internal override void ProcessResponse(HttpResponseMessage response)
private static RestReturnType CheckReturnType(HttpResponseMessage response)
{
- ArgumentNullException.ThrowIfNull(response);
+ if (response == null) { throw new ArgumentNullException(nameof(response)); }
RestReturnType rt = RestReturnType.Detect;
string contentType = ContentHelper.GetContentType(response);
diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/CommandLineParameterParser.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/CommandLineParameterParser.cs
index 30106d9a1e7..9b92ecbc204 100644
--- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/CommandLineParameterParser.cs
+++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/CommandLineParameterParser.cs
@@ -835,7 +835,10 @@ internal void Parse(string[] args)
for (int i = 0; i < args.Length; i++)
{
- ArgumentNullException.ThrowIfNull(args[i], CommandLineParameterParserStrings.NullElementInArgs);
+ if (args[i] is null)
+ {
+ throw new ArgumentNullException(nameof(args), CommandLineParameterParserStrings.NullElementInArgs);
+ }
}
// Indicates that we've called this method on this instance, and that when it's done, the state variables
diff --git a/src/Microsoft.PowerShell.CoreCLR.Eventing/DotNetCode/Eventing/EventProviderTraceListener.cs b/src/Microsoft.PowerShell.CoreCLR.Eventing/DotNetCode/Eventing/EventProviderTraceListener.cs
index 1c82891b654..94eb340b21c 100644
--- a/src/Microsoft.PowerShell.CoreCLR.Eventing/DotNetCode/Eventing/EventProviderTraceListener.cs
+++ b/src/Microsoft.PowerShell.CoreCLR.Eventing/DotNetCode/Eventing/EventProviderTraceListener.cs
@@ -41,7 +41,8 @@ public string Delimiter
[SuppressMessage("Microsoft.Usage", "CA2208:InstantiateArgumentExceptionsCorrectly")]
set
{
- ArgumentNullException.ThrowIfNull(value, nameof(Delimiter));
+ if (value == null)
+ throw new ArgumentNullException(nameof(Delimiter));
if (value.Length == 0)
throw new ArgumentException(DotNetEventingStrings.Argument_NeedNonemptyDelimiter);
diff --git a/src/Microsoft.WSMan.Management/ConfigProvider.cs b/src/Microsoft.WSMan.Management/ConfigProvider.cs
index d40e4161188..9429c6ef4e7 100644
--- a/src/Microsoft.WSMan.Management/ConfigProvider.cs
+++ b/src/Microsoft.WSMan.Management/ConfigProvider.cs
@@ -3413,7 +3413,7 @@ private static string NormalizePath(string path, string host)
///
private PSObject GetItemValue(string path)
{
- if (string.IsNullOrEmpty(path))
+ if (string.IsNullOrEmpty(path) || (path.Length == 0))
{
throw new ArgumentNullException(path);
}
diff --git a/src/System.Management.Automation/CoreCLR/CorePsAssemblyLoadContext.cs b/src/System.Management.Automation/CoreCLR/CorePsAssemblyLoadContext.cs
index 6a9462f37d4..47b02d7d131 100644
--- a/src/System.Management.Automation/CoreCLR/CorePsAssemblyLoadContext.cs
+++ b/src/System.Management.Automation/CoreCLR/CorePsAssemblyLoadContext.cs
@@ -580,9 +580,7 @@ public static class PowerShellAssemblyLoadContextInitializer
public static void SetPowerShellAssemblyLoadContext([MarshalAs(UnmanagedType.LPWStr)] string basePaths)
{
if (string.IsNullOrEmpty(basePaths))
- {
throw new ArgumentNullException(nameof(basePaths));
- }
PowerShellAssemblyLoadContext.InitializeSingleton(basePaths);
}
diff --git a/src/System.Management.Automation/engine/ComInterop/Helpers.cs b/src/System.Management.Automation/engine/ComInterop/Helpers.cs
index 814e93825a7..513c3126476 100644
--- a/src/System.Management.Automation/engine/ComInterop/Helpers.cs
+++ b/src/System.Management.Automation/engine/ComInterop/Helpers.cs
@@ -35,7 +35,10 @@ internal static class Requires
[System.Diagnostics.Conditional("DEBUG")]
internal static void NotNull(object value, string paramName)
{
- ArgumentNullException.ThrowIfNull(value, paramName);
+ if (value == null)
+ {
+ throw new ArgumentNullException(paramName);
+ }
}
[System.Diagnostics.Conditional("DEBUG")]
diff --git a/src/System.Management.Automation/engine/DefaultCommandRuntime.cs b/src/System.Management.Automation/engine/DefaultCommandRuntime.cs
index 88a2a2ee427..48d74667dae 100644
--- a/src/System.Management.Automation/engine/DefaultCommandRuntime.cs
+++ b/src/System.Management.Automation/engine/DefaultCommandRuntime.cs
@@ -21,7 +21,8 @@ internal class DefaultCommandRuntime : ICommandRuntime2
///
public DefaultCommandRuntime(List