diff --git a/src/Microsoft.PowerShell.Commands.Management/cimSupport/cmdletization/SessionBasedWrapper.cs b/src/Microsoft.PowerShell.Commands.Management/cimSupport/cmdletization/SessionBasedWrapper.cs index 9ad44f3a07f..f60dc86e873 100644 --- a/src/Microsoft.PowerShell.Commands.Management/cimSupport/cmdletization/SessionBasedWrapper.cs +++ b/src/Microsoft.PowerShell.Commands.Management/cimSupport/cmdletization/SessionBasedWrapper.cs @@ -81,7 +81,7 @@ protected TSession[] Session { if (value == null) { - throw new ArgumentNullException("value"); + throw new ArgumentNullException(nameof(value)); } _session = value; diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetRandomCommand.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetRandomCommand.cs index 01cf6534c48..35e5ed11989 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetRandomCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetRandomCommand.cs @@ -87,12 +87,12 @@ private void ThrowMinGreaterThanOrEqualMax(object minValue, object maxValue) { if (minValue == null) { - throw PSTraceSource.NewArgumentNullException("min"); + throw PSTraceSource.NewArgumentNullException(nameof(minValue)); } if (maxValue == null) { - throw PSTraceSource.NewArgumentNullException("max"); + throw PSTraceSource.NewArgumentNullException(nameof(maxValue)); } ErrorRecord errorRecord = new ErrorRecord( diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/MatchString.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/MatchString.cs index 3a5d4c77a5f..e3501349055 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/MatchString.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/MatchString.cs @@ -544,7 +544,7 @@ public void CopyTo(T[] array, int arrayIndex) if (Count > (array.Length - arrayIndex)) { - throw new ArgumentException("arrayIndex"); + throw new ArgumentException(null, nameof(arrayIndex)); } // Iterate through the buffer in correct order. @@ -1312,7 +1312,7 @@ public string[] Exclude { // null check is not needed (because of ValidateNotNullOrEmpty), // but we have to include it to silence OACR - _excludeStrings = value ?? throw PSTraceSource.NewArgumentNullException("value"); + _excludeStrings = value ?? throw PSTraceSource.NewArgumentNullException(nameof(value)); _exclude = new WildcardPattern[_excludeStrings.Length]; for (int i = 0; i < _excludeStrings.Length; i++) @@ -1370,7 +1370,7 @@ public string[] Exclude { // null check is not needed (because of ValidateNotNullOrEmpty), // but we have to include it to silence OACR - _context = value ?? throw PSTraceSource.NewArgumentNullException("value"); + _context = value ?? throw PSTraceSource.NewArgumentNullException(nameof(value)); if (_context.Length == 1) { diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs index f38446ed57f..be0bf30e84b 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs @@ -1864,7 +1864,7 @@ private void AddMultipartContent(object fieldName, object fieldValue, MultipartF { if (formData == null) { - throw new ArgumentNullException("formDate"); + throw new ArgumentNullException(nameof(formData)); } // It is possible that the dictionary keys or values are PSObject wrapped depending on how the dictionary is defined and assigned. diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostRawUserInterface.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostRawUserInterface.cs index 91aceef2fbd..8727ce5758e 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostRawUserInterface.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostRawUserInterface.cs @@ -112,7 +112,7 @@ public override } else { - throw PSTraceSource.NewArgumentException("value", ConsoleHostRawUserInterfaceStrings.InvalidConsoleColorError); + throw PSTraceSource.NewArgumentException(nameof(value), ConsoleHostRawUserInterfaceStrings.InvalidConsoleColorError); } } } @@ -163,7 +163,7 @@ public override } else { - throw PSTraceSource.NewArgumentException("value", ConsoleHostRawUserInterfaceStrings.InvalidConsoleColorError); + throw PSTraceSource.NewArgumentException(nameof(value), ConsoleHostRawUserInterfaceStrings.InvalidConsoleColorError); } } } @@ -844,7 +844,7 @@ public override string WindowTitle } else { - throw PSTraceSource.NewArgumentNullException("value"); + throw PSTraceSource.NewArgumentNullException(nameof(value)); } } } @@ -1218,7 +1218,7 @@ int LengthInBufferCells(string s) /// /// See base class. /// - /// + /// /// /// /// @@ -1226,14 +1226,14 @@ int LengthInBufferCells(string s) /// public override - int LengthInBufferCells(string s, int offset) + int LengthInBufferCells(string str, int offset) { - if (s == null) + if (str == null) { - throw PSTraceSource.NewArgumentNullException("str"); + throw PSTraceSource.NewArgumentNullException(nameof(str)); } - return ConsoleControl.LengthInBufferCells(s, offset, parent.SupportsVirtualTerminal); + return ConsoleControl.LengthInBufferCells(str, offset, parent.SupportsVirtualTerminal); } /// @@ -1622,7 +1622,7 @@ public override void SetBufferContents(Coordinates origin, // if there are no contents, there is nothing to set the buffer to if (contents == null) { - PSTraceSource.NewArgumentNullException("contents"); + PSTraceSource.NewArgumentNullException(nameof(contents)); } // if the cursor is on the last line, we need to make more space to print the specified buffer if (origin.Y == BufferSize.Height - 1 && origin.X >= BufferSize.Width) @@ -1695,19 +1695,19 @@ int LengthInBufferCells(string s) /// /// See base class. /// - /// + /// /// /// public override - int LengthInBufferCells(string s, int offset) + int LengthInBufferCells(string str, int offset) { - if (s == null) + if (str == null) { - throw PSTraceSource.NewArgumentNullException("str"); + throw PSTraceSource.NewArgumentNullException(nameof(str)); } - return ConsoleControl.LengthInBufferCells(s, offset, _parent.SupportsVirtualTerminal); + return ConsoleControl.LengthInBufferCells(str, offset, _parent.SupportsVirtualTerminal); } } } diff --git a/src/Microsoft.WSMan.Management/ConfigProvider.cs b/src/Microsoft.WSMan.Management/ConfigProvider.cs index 326f53d4d94..bedfcc2c357 100644 --- a/src/Microsoft.WSMan.Management/ConfigProvider.cs +++ b/src/Microsoft.WSMan.Management/ConfigProvider.cs @@ -875,7 +875,7 @@ protected override void SetItem(string path, object value) { if (value == null) { - throw new ArgumentException(helper.GetResourceMsgFromResourcetext("value")); + throw new ArgumentException(helper.GetResourceMsgFromResourcetext(nameof(value))); } string ChildName = string.Empty; diff --git a/src/System.Management.Automation/DscSupport/CimDSCParser.cs b/src/System.Management.Automation/DscSupport/CimDSCParser.cs index 58fc81715bb..2406a7acd44 100644 --- a/src/System.Management.Automation/DscSupport/CimDSCParser.cs +++ b/src/System.Management.Automation/DscSupport/CimDSCParser.cs @@ -2189,7 +2189,7 @@ private static void LoadPowerShellClassResourcesFromModule(PSModuleInfo primaryM if (moduleInfo.ModuleType == ModuleType.Binary) { #if CORECLR - throw PSTraceSource.NewArgumentException("isConfiguration", ParserStrings.ConfigurationNotSupportedInPowerShellCore); + throw PSTraceSource.NewArgumentException(nameof(moduleInfo), ParserStrings.ConfigurationNotSupportedInPowerShellCore); #else ResolveEventHandler reh = (sender, args) => CurrentDomain_ReflectionOnlyAssemblyResolve(sender, args, moduleInfo); diff --git a/src/System.Management.Automation/FormatAndOutput/common/BaseOutputtingCommand.cs b/src/System.Management.Automation/FormatAndOutput/common/BaseOutputtingCommand.cs index bb8305b2fdc..d8a92c6c818 100644 --- a/src/System.Management.Automation/FormatAndOutput/common/BaseOutputtingCommand.cs +++ b/src/System.Management.Automation/FormatAndOutput/common/BaseOutputtingCommand.cs @@ -513,7 +513,7 @@ private void ProcessPayload(FormatEntryData fed, FormatMessagesContextManager.Ou if (fed.formatEntryInfo == null) { - PSTraceSource.NewArgumentNullException("fed.formatEntryInfo"); + PSTraceSource.NewArgumentException(nameof(fed), "fed.formatEntryInfo is null"); } WriteStreamType oldWSState = _lo.WriteStream; diff --git a/src/System.Management.Automation/FormatAndOutput/common/DisplayDatabase/displayDescriptionData.cs b/src/System.Management.Automation/FormatAndOutput/common/DisplayDatabase/displayDescriptionData.cs index 64af2244fb8..f467c05608e 100644 --- a/src/System.Management.Automation/FormatAndOutput/common/DisplayDatabase/displayDescriptionData.cs +++ b/src/System.Management.Automation/FormatAndOutput/common/DisplayDatabase/displayDescriptionData.cs @@ -819,7 +819,7 @@ internal DisplayEntry(ExpressionToken expression) if (string.IsNullOrEmpty(Value)) if (Value == null || ValueType == DisplayEntryValueType.Property) - throw PSTraceSource.NewArgumentNullException("value"); + throw PSTraceSource.NewArgumentException(nameof(expression)); } internal bool SafeForExport() diff --git a/src/System.Management.Automation/FormatAndOutput/common/DisplayDatabase/displayDescriptionData_Table.cs b/src/System.Management.Automation/FormatAndOutput/common/DisplayDatabase/displayDescriptionData_Table.cs index b9d1e897068..78b084d7f6c 100644 --- a/src/System.Management.Automation/FormatAndOutput/common/DisplayDatabase/displayDescriptionData_Table.cs +++ b/src/System.Management.Automation/FormatAndOutput/common/DisplayDatabase/displayDescriptionData_Table.cs @@ -291,7 +291,7 @@ internal TableControl(TableControlBody tcb, ViewDefinition viewDefinition) : thi public TableControl(TableControlRow tableControlRow) : this() { if (tableControlRow == null) - throw PSTraceSource.NewArgumentNullException("tableControlRows"); + throw PSTraceSource.NewArgumentNullException(nameof(tableControlRow)); this.Rows.Add(tableControlRow); } @@ -304,7 +304,7 @@ public TableControl(TableControlRow tableControlRow) : this() public TableControl(TableControlRow tableControlRow, IEnumerable tableControlColumnHeaders) : this() { if (tableControlRow == null) - throw PSTraceSource.NewArgumentNullException("tableControlRows"); + throw PSTraceSource.NewArgumentNullException(nameof(tableControlRow)); if (tableControlColumnHeaders == null) throw PSTraceSource.NewArgumentNullException(nameof(tableControlColumnHeaders)); diff --git a/src/System.Management.Automation/FormatAndOutput/common/DisplayDatabase/typeDataXmlLoader.cs b/src/System.Management.Automation/FormatAndOutput/common/DisplayDatabase/typeDataXmlLoader.cs index 79bcbd61dca..c1b9bf2d1cb 100644 --- a/src/System.Management.Automation/FormatAndOutput/common/DisplayDatabase/typeDataXmlLoader.cs +++ b/src/System.Management.Automation/FormatAndOutput/common/DisplayDatabase/typeDataXmlLoader.cs @@ -425,7 +425,7 @@ private void LoadData(XmlDocument doc, TypeInfoDataBase db) private void LoadData(ExtendedTypeDefinition typeDefinition, TypeInfoDataBase db, bool isForHelpOutput) { if (typeDefinition == null) - throw PSTraceSource.NewArgumentNullException("viewDefinition"); + throw PSTraceSource.NewArgumentNullException(nameof(typeDefinition)); if (db == null) throw PSTraceSource.NewArgumentNullException(nameof(db)); diff --git a/src/System.Management.Automation/FormatAndOutput/common/FormattingObjectsDeserializer.cs b/src/System.Management.Automation/FormatAndOutput/common/FormattingObjectsDeserializer.cs index 21630c1a9c1..ade1a9a70e2 100644 --- a/src/System.Management.Automation/FormatAndOutput/common/FormattingObjectsDeserializer.cs +++ b/src/System.Management.Automation/FormatAndOutput/common/FormattingObjectsDeserializer.cs @@ -402,7 +402,7 @@ internal static FormatInfoData CreateInstance(PSObject so, FormatObjectDeseriali string msg = StringUtil.Format(FormatAndOut_format_xxx.FOD_InvalidClassidProperty); ErrorRecord errorRecord = new ErrorRecord( - PSTraceSource.NewArgumentException("classid"), + PSTraceSource.NewArgumentException(nameof(classId)), "FormatObjectDeserializerInvalidClassidProperty", ErrorCategory.InvalidData, so); diff --git a/src/System.Management.Automation/engine/CommandDiscovery.cs b/src/System.Management.Automation/engine/CommandDiscovery.cs index ef9cb56c636..a0d3424be50 100644 --- a/src/System.Management.Automation/engine/CommandDiscovery.cs +++ b/src/System.Management.Automation/engine/CommandDiscovery.cs @@ -207,7 +207,7 @@ internal CmdletInfo AddCmdletInfoToCache(string name, CmdletInfo newCmdletInfo, if (newCmdletInfo == null) { - throw PSTraceSource.NewArgumentNullException("cmdlet"); + throw PSTraceSource.NewArgumentNullException(nameof(newCmdletInfo)); } if (isGlobal) diff --git a/src/System.Management.Automation/engine/FunctionInfo.cs b/src/System.Management.Automation/engine/FunctionInfo.cs index 8afe41ece15..aa1fb91fce8 100644 --- a/src/System.Management.Automation/engine/FunctionInfo.cs +++ b/src/System.Management.Automation/engine/FunctionInfo.cs @@ -222,7 +222,7 @@ internal void Update(ScriptBlock newFunction, bool force, ScopedItemOptions opti { if (newFunction == null) { - throw PSTraceSource.NewArgumentNullException("function"); + throw PSTraceSource.NewArgumentNullException(nameof(newFunction)); } if ((_options & ScopedItemOptions.Constant) != 0) diff --git a/src/System.Management.Automation/engine/GetCommandCommand.cs b/src/System.Management.Automation/engine/GetCommandCommand.cs index afc2b12393b..c20f499d8e2 100644 --- a/src/System.Management.Automation/engine/GetCommandCommand.cs +++ b/src/System.Management.Automation/engine/GetCommandCommand.cs @@ -286,7 +286,7 @@ public string[] ParameterName { if (value == null) { - throw new ArgumentNullException("value"); + throw new ArgumentNullException(nameof(value)); } _parameterNames = value; @@ -316,7 +316,7 @@ public PSTypeName[] ParameterType { if (value == null) { - throw new ArgumentNullException("value"); + throw new ArgumentNullException(nameof(value)); } // if '...CimInstance#Win32_Process' is specified, then exclude '...CimInstance' diff --git a/src/System.Management.Automation/engine/MshCommandRuntime.cs b/src/System.Management.Automation/engine/MshCommandRuntime.cs index 4d07cd3d3a8..f2971c4f95e 100644 --- a/src/System.Management.Automation/engine/MshCommandRuntime.cs +++ b/src/System.Management.Automation/engine/MshCommandRuntime.cs @@ -2767,7 +2767,7 @@ private void DoWriteError(object obj) ActionPreference preference = pair.Value; if (errorRecord == null) { - throw PSTraceSource.NewArgumentNullException("errorRecord"); + throw PSTraceSource.NewArgumentException(nameof(obj), "errorRecord is null"); } // If this error came from a transacted cmdlet, diff --git a/src/System.Management.Automation/engine/MshSnapinQualifiedName.cs b/src/System.Management.Automation/engine/MshSnapinQualifiedName.cs index b23df2202eb..74227ab41b1 100644 --- a/src/System.Management.Automation/engine/MshSnapinQualifiedName.cs +++ b/src/System.Management.Automation/engine/MshSnapinQualifiedName.cs @@ -35,7 +35,7 @@ private PSSnapinQualifiedName(string[] splitName) // Since the provider name contained multiple slashes it is // a bad format. - throw PSTraceSource.NewArgumentException("name"); + throw PSTraceSource.NewArgumentException(nameof(splitName)); } // Now set the full name diff --git a/src/System.Management.Automation/engine/ProgressRecord.cs b/src/System.Management.Automation/engine/ProgressRecord.cs index f040e24e416..1d342d89a69 100644 --- a/src/System.Management.Automation/engine/ProgressRecord.cs +++ b/src/System.Management.Automation/engine/ProgressRecord.cs @@ -43,17 +43,17 @@ class ProgressRecord { // negative Ids are reserved to indicate "no id" for parent Ids. - throw PSTraceSource.NewArgumentOutOfRangeException(nameof(activityId), activityId, ProgressRecordStrings.ArgMayNotBeNegative, "activityId"); + throw PSTraceSource.NewArgumentOutOfRangeException(nameof(activityId), activityId, ProgressRecordStrings.ArgMayNotBeNegative, nameof(activityId)); } if (string.IsNullOrEmpty(activity)) { - throw PSTraceSource.NewArgumentException(nameof(activity), ProgressRecordStrings.ArgMayNotBeNullOrEmpty, "activity"); + throw PSTraceSource.NewArgumentException(nameof(activity), ProgressRecordStrings.ArgMayNotBeNullOrEmpty, nameof(activity)); } if (string.IsNullOrEmpty(statusDescription)) { - throw PSTraceSource.NewArgumentException(nameof(activity), ProgressRecordStrings.ArgMayNotBeNullOrEmpty, "statusDescription"); + throw PSTraceSource.NewArgumentException(nameof(statusDescription), ProgressRecordStrings.ArgMayNotBeNullOrEmpty, nameof(statusDescription)); } this.id = activityId; @@ -121,7 +121,7 @@ internal ProgressRecord(ProgressRecord other) { if (value == ActivityId) { - throw PSTraceSource.NewArgumentException("value", ProgressRecordStrings.ParentActivityIdCantBeActivityId); + throw PSTraceSource.NewArgumentException(nameof(value), ProgressRecordStrings.ParentActivityIdCantBeActivityId); } parentId = value; @@ -149,7 +149,7 @@ internal ProgressRecord(ProgressRecord other) { if (string.IsNullOrEmpty(value)) { - throw PSTraceSource.NewArgumentException("value", ProgressRecordStrings.ArgMayNotBeNullOrEmpty, "value"); + throw PSTraceSource.NewArgumentException(nameof(value), ProgressRecordStrings.ArgMayNotBeNullOrEmpty, nameof(value)); } activity = value; @@ -173,7 +173,7 @@ internal ProgressRecord(ProgressRecord other) { if (string.IsNullOrEmpty(value)) { - throw PSTraceSource.NewArgumentException("value", ProgressRecordStrings.ArgMayNotBeNullOrEmpty, "value"); + throw PSTraceSource.NewArgumentException(nameof(value), ProgressRecordStrings.ArgMayNotBeNullOrEmpty, nameof(value)); } status = value; @@ -276,7 +276,7 @@ internal ProgressRecord(ProgressRecord other) { if (value != ProgressRecordType.Completed && value != ProgressRecordType.Processing) { - throw PSTraceSource.NewArgumentException("value"); + throw PSTraceSource.NewArgumentException(nameof(value)); } type = value; diff --git a/src/System.Management.Automation/engine/ProxyCommand.cs b/src/System.Management.Automation/engine/ProxyCommand.cs index 1bb3d15baf3..ede1eee6da3 100644 --- a/src/System.Management.Automation/engine/ProxyCommand.cs +++ b/src/System.Management.Automation/engine/ProxyCommand.cs @@ -41,7 +41,7 @@ public static string Create(CommandMetadata commandMetadata) { if (commandMetadata == null) { - throw PSTraceSource.NewArgumentNullException("commandMetaData"); + throw PSTraceSource.NewArgumentNullException(nameof(commandMetadata)); } return commandMetadata.GetProxyCommand(string.Empty, true); @@ -67,7 +67,7 @@ public static string Create(CommandMetadata commandMetadata, string helpComment) { if (commandMetadata == null) { - throw PSTraceSource.NewArgumentNullException("commandMetaData"); + throw PSTraceSource.NewArgumentNullException(nameof(commandMetadata)); } return commandMetadata.GetProxyCommand(helpComment, true); @@ -97,7 +97,7 @@ public static string Create(CommandMetadata commandMetadata, string helpComment, { if (commandMetadata == null) { - throw PSTraceSource.NewArgumentNullException("commandMetaData"); + throw PSTraceSource.NewArgumentNullException(nameof(commandMetadata)); } return commandMetadata.GetProxyCommand(helpComment, generateDynamicParameters); @@ -120,7 +120,7 @@ public static string GetCmdletBindingAttribute(CommandMetadata commandMetadata) { if (commandMetadata == null) { - throw PSTraceSource.NewArgumentNullException("commandMetaData"); + throw PSTraceSource.NewArgumentNullException(nameof(commandMetadata)); } return commandMetadata.GetDecl(); @@ -145,7 +145,7 @@ public static string GetParamBlock(CommandMetadata commandMetadata) { if (commandMetadata == null) { - throw PSTraceSource.NewArgumentNullException("commandMetaData"); + throw PSTraceSource.NewArgumentNullException(nameof(commandMetadata)); } return commandMetadata.GetParamBlock(); @@ -169,7 +169,7 @@ public static string GetBegin(CommandMetadata commandMetadata) { if (commandMetadata == null) { - throw PSTraceSource.NewArgumentNullException("commandMetaData"); + throw PSTraceSource.NewArgumentNullException(nameof(commandMetadata)); } return commandMetadata.GetBeginBlock(); @@ -193,7 +193,7 @@ public static string GetProcess(CommandMetadata commandMetadata) { if (commandMetadata == null) { - throw PSTraceSource.NewArgumentNullException("commandMetaData"); + throw PSTraceSource.NewArgumentNullException(nameof(commandMetadata)); } return commandMetadata.GetProcessBlock(); @@ -217,7 +217,7 @@ public static string GetDynamicParam(CommandMetadata commandMetadata) { if (commandMetadata == null) { - throw PSTraceSource.NewArgumentNullException("commandMetaData"); + throw PSTraceSource.NewArgumentNullException(nameof(commandMetadata)); } return commandMetadata.GetDynamicParamBlock(); @@ -241,7 +241,7 @@ public static string GetEnd(CommandMetadata commandMetadata) { if (commandMetadata == null) { - throw PSTraceSource.NewArgumentNullException("commandMetaData"); + throw PSTraceSource.NewArgumentNullException(nameof(commandMetadata)); } return commandMetadata.GetEndBlock(); diff --git a/src/System.Management.Automation/engine/PseudoParameters.cs b/src/System.Management.Automation/engine/PseudoParameters.cs index 78ef034cf5b..4bb4e97bca2 100644 --- a/src/System.Management.Automation/engine/PseudoParameters.cs +++ b/src/System.Management.Automation/engine/PseudoParameters.cs @@ -87,7 +87,7 @@ public string Name { if (string.IsNullOrEmpty(value)) { - throw PSTraceSource.NewArgumentException("name"); + throw PSTraceSource.NewArgumentException(nameof(value)); } _name = value; @@ -116,7 +116,7 @@ public Type ParameterType { if (value == null) { - throw PSTraceSource.NewArgumentNullException("value"); + throw PSTraceSource.NewArgumentNullException(nameof(value)); } _parameterType = value; diff --git a/src/System.Management.Automation/engine/SessionStateDriveAPIs.cs b/src/System.Management.Automation/engine/SessionStateDriveAPIs.cs index 23e9fdc0475..b6294acdbd9 100644 --- a/src/System.Management.Automation/engine/SessionStateDriveAPIs.cs +++ b/src/System.Management.Automation/engine/SessionStateDriveAPIs.cs @@ -223,7 +223,7 @@ internal void NewDrive(PSDriveInfo drive, string scopeID, CmdletProviderContext SessionStateStrings.NewDriveProviderFailed, drive.Provider, drive.Root, - PSTraceSource.NewArgumentException("root")); + PSTraceSource.NewArgumentException(nameof(drive))); throw e; } diff --git a/src/System.Management.Automation/engine/TypeTable.cs b/src/System.Management.Automation/engine/TypeTable.cs index c5b889b2586..94ee89eff22 100644 --- a/src/System.Management.Automation/engine/TypeTable.cs +++ b/src/System.Management.Automation/engine/TypeTable.cs @@ -2193,7 +2193,7 @@ public TypeMemberData StringSerializationSourceProperty if (!(value is NotePropertyData || value is ScriptPropertyData || value is CodePropertyData)) { - throw PSTraceSource.NewArgumentException("value"); + throw PSTraceSource.NewArgumentException(nameof(value)); } // Remove existing property @@ -3930,7 +3930,7 @@ internal TypeTable(IEnumerable typeFiles, AuthorizationManager authoriza { if (string.IsNullOrEmpty(typefile) || (!Path.IsPathRooted(typefile))) { - throw PSTraceSource.NewArgumentException("typeFile", TypesXmlStrings.TypeFileNotRooted, typefile); + throw PSTraceSource.NewArgumentException(nameof(typefile), TypesXmlStrings.TypeFileNotRooted, typefile); } bool unused; diff --git a/src/System.Management.Automation/engine/hostifaces/ChoiceDescription.cs b/src/System.Management.Automation/engine/hostifaces/ChoiceDescription.cs index 9fca84d4a33..979db794fcd 100644 --- a/src/System.Management.Automation/engine/hostifaces/ChoiceDescription.cs +++ b/src/System.Management.Automation/engine/hostifaces/ChoiceDescription.cs @@ -38,7 +38,7 @@ class ChoiceDescription if (string.IsNullOrEmpty(label)) { // "label" is not localizable - throw PSTraceSource.NewArgumentException(nameof(label), DescriptionsStrings.NullOrEmptyErrorTemplate, "label"); + throw PSTraceSource.NewArgumentException(nameof(label), DescriptionsStrings.NullOrEmptyErrorTemplate, nameof(label)); } this.label = label; @@ -68,7 +68,7 @@ class ChoiceDescription if (string.IsNullOrEmpty(label)) { // "label" is not localizable - throw PSTraceSource.NewArgumentException(nameof(label), DescriptionsStrings.NullOrEmptyErrorTemplate, "label"); + throw PSTraceSource.NewArgumentException(nameof(label), DescriptionsStrings.NullOrEmptyErrorTemplate, nameof(label)); } if (helpMessage == null) @@ -131,7 +131,7 @@ class ChoiceDescription { if (value == null) { - throw PSTraceSource.NewArgumentNullException("value"); + throw PSTraceSource.NewArgumentNullException(nameof(value)); } this.helpMessage = value; diff --git a/src/System.Management.Automation/engine/hostifaces/FieldDescription.cs b/src/System.Management.Automation/engine/hostifaces/FieldDescription.cs index 545440a1574..90f0820c9ff 100644 --- a/src/System.Management.Automation/engine/hostifaces/FieldDescription.cs +++ b/src/System.Management.Automation/engine/hostifaces/FieldDescription.cs @@ -43,7 +43,7 @@ public class if (string.IsNullOrEmpty(name)) { - throw PSTraceSource.NewArgumentException(nameof(name), DescriptionsStrings.NullOrEmptyErrorTemplate, "name"); + throw PSTraceSource.NewArgumentException(nameof(name), DescriptionsStrings.NullOrEmptyErrorTemplate, nameof(name)); } this.name = name; @@ -205,7 +205,7 @@ public string Name { if (value == null) { - throw PSTraceSource.NewArgumentNullException("value"); + throw PSTraceSource.NewArgumentNullException(nameof(value)); } label = value; @@ -238,7 +238,7 @@ public string Name { if (value == null) { - throw PSTraceSource.NewArgumentNullException("value"); + throw PSTraceSource.NewArgumentNullException(nameof(value)); } helpMessage = value; @@ -319,7 +319,7 @@ public string Name { if (string.IsNullOrEmpty(nameOfType)) { - throw PSTraceSource.NewArgumentException(nameof(nameOfType), DescriptionsStrings.NullOrEmptyErrorTemplate, "nameOfType"); + throw PSTraceSource.NewArgumentException(nameof(nameOfType), DescriptionsStrings.NullOrEmptyErrorTemplate, nameof(nameOfType)); } parameterTypeName = nameOfType; @@ -339,7 +339,7 @@ public string Name { if (string.IsNullOrEmpty(fullNameOfType)) { - throw PSTraceSource.NewArgumentException(nameof(fullNameOfType), DescriptionsStrings.NullOrEmptyErrorTemplate, "fullNameOfType"); + throw PSTraceSource.NewArgumentException(nameof(fullNameOfType), DescriptionsStrings.NullOrEmptyErrorTemplate, nameof(fullNameOfType)); } parameterTypeFullName = fullNameOfType; @@ -359,7 +359,7 @@ public string Name { if (string.IsNullOrEmpty(fullNameOfAssembly)) { - throw PSTraceSource.NewArgumentException(nameof(fullNameOfAssembly), DescriptionsStrings.NullOrEmptyErrorTemplate, "fullNameOfAssembly"); + throw PSTraceSource.NewArgumentException(nameof(fullNameOfAssembly), DescriptionsStrings.NullOrEmptyErrorTemplate, nameof(fullNameOfAssembly)); } parameterAssemblyFullName = fullNameOfAssembly; diff --git a/src/System.Management.Automation/engine/hostifaces/InternalHostUserInterface.cs b/src/System.Management.Automation/engine/hostifaces/InternalHostUserInterface.cs index 1e2478d7bd2..f9bc360047d 100644 --- a/src/System.Management.Automation/engine/hostifaces/InternalHostUserInterface.cs +++ b/src/System.Management.Automation/engine/hostifaces/InternalHostUserInterface.cs @@ -778,7 +778,7 @@ public override if (descriptions.Count < 1) { - throw PSTraceSource.NewArgumentException(nameof(descriptions), InternalHostUserInterfaceStrings.PromptEmptyDescriptionsError, "descriptions"); + throw PSTraceSource.NewArgumentException(nameof(descriptions), InternalHostUserInterfaceStrings.PromptEmptyDescriptionsError, nameof(descriptions)); } if (_externalUI == null) diff --git a/src/System.Management.Automation/engine/hostifaces/MshHostRawUserInterface.cs b/src/System.Management.Automation/engine/hostifaces/MshHostRawUserInterface.cs index 79f4bcff66a..23413d71258 100644 --- a/src/System.Management.Automation/engine/hostifaces/MshHostRawUserInterface.cs +++ b/src/System.Management.Automation/engine/hostifaces/MshHostRawUserInterface.cs @@ -794,13 +794,13 @@ public int Bottom if (right < left) { // "right" and "left" are not localizable - throw PSTraceSource.NewArgumentException(nameof(right), MshHostRawUserInterfaceStrings.LessThanErrorTemplate, "right", "left"); + throw PSTraceSource.NewArgumentException(nameof(right), MshHostRawUserInterfaceStrings.LessThanErrorTemplate, nameof(right), nameof(left)); } if (bottom < top) { // "bottom" and "top" are not localizable - throw PSTraceSource.NewArgumentException(nameof(bottom), MshHostRawUserInterfaceStrings.LessThanErrorTemplate, "bottom", "top"); + throw PSTraceSource.NewArgumentException(nameof(bottom), MshHostRawUserInterfaceStrings.LessThanErrorTemplate, nameof(bottom), nameof(top)); } this.left = left; diff --git a/src/System.Management.Automation/engine/hostifaces/PSCommand.cs b/src/System.Management.Automation/engine/hostifaces/PSCommand.cs index 781e53eaf51..3e5231a413c 100644 --- a/src/System.Management.Automation/engine/hostifaces/PSCommand.cs +++ b/src/System.Management.Automation/engine/hostifaces/PSCommand.cs @@ -89,7 +89,7 @@ public PSCommand AddCommand(string command) { if (command == null) { - throw PSTraceSource.NewArgumentNullException("cmdlet"); + throw PSTraceSource.NewArgumentNullException(nameof(command)); } if (_owner != null) diff --git a/src/System.Management.Automation/engine/parser/GlobalAssemblyCache.cs b/src/System.Management.Automation/engine/parser/GlobalAssemblyCache.cs index 467f3f2c5e7..da89531d245 100644 --- a/src/System.Management.Automation/engine/parser/GlobalAssemblyCache.cs +++ b/src/System.Management.Automation/engine/parser/GlobalAssemblyCache.cs @@ -164,7 +164,7 @@ public static unsafe string ResolvePartialName( { if (displayName == null) { - throw new ArgumentNullException("displayName"); + throw new ArgumentNullException(nameof(displayName)); } location = null; diff --git a/src/System.Management.Automation/engine/remoting/client/Job2.cs b/src/System.Management.Automation/engine/remoting/client/Job2.cs index 32923806cce..1e60fb2a10d 100644 --- a/src/System.Management.Automation/engine/remoting/client/Job2.cs +++ b/src/System.Management.Automation/engine/remoting/client/Job2.cs @@ -105,7 +105,7 @@ public List StartParameters { if (value == null) { - throw PSTraceSource.NewArgumentNullException("value"); + throw PSTraceSource.NewArgumentNullException(nameof(value)); } lock (_syncobject) diff --git a/src/System.Management.Automation/engine/remoting/client/JobSourceAdapter.cs b/src/System.Management.Automation/engine/remoting/client/JobSourceAdapter.cs index f38ac4a39d0..bc97fe66cb9 100644 --- a/src/System.Management.Automation/engine/remoting/client/JobSourceAdapter.cs +++ b/src/System.Management.Automation/engine/remoting/client/JobSourceAdapter.cs @@ -188,7 +188,7 @@ public string Name set { if (value == null) - throw new PSArgumentNullException("value"); + throw new PSArgumentNullException(nameof(value)); _name = value; } } diff --git a/src/System.Management.Automation/engine/remoting/client/RemoteRunspacePoolInternal.cs b/src/System.Management.Automation/engine/remoting/client/RemoteRunspacePoolInternal.cs index 7c2aceec7d4..5ef36bb912a 100644 --- a/src/System.Management.Automation/engine/remoting/client/RemoteRunspacePoolInternal.cs +++ b/src/System.Management.Automation/engine/remoting/client/RemoteRunspacePoolInternal.cs @@ -71,7 +71,7 @@ internal RemoteRunspacePoolInternal(int minRunspaces, { if (connectionInfo == null) { - throw PSTraceSource.NewArgumentNullException("WSManConnectionInfo"); + throw PSTraceSource.NewArgumentNullException(nameof(connectionInfo)); } PSEtwLog.LogOperationalVerbose(PSEventId.RunspacePoolConstructor, diff --git a/src/System.Management.Automation/engine/remoting/common/RunspaceConnectionInfo.cs b/src/System.Management.Automation/engine/remoting/common/RunspaceConnectionInfo.cs index 7f46151a857..64f7c038fe2 100644 --- a/src/System.Management.Automation/engine/remoting/common/RunspaceConnectionInfo.cs +++ b/src/System.Management.Automation/engine/remoting/common/RunspaceConnectionInfo.cs @@ -168,7 +168,7 @@ public CultureInfo Culture { if (value == null) { - throw new ArgumentNullException("value"); + throw new ArgumentNullException(nameof(value)); } _culture = value; @@ -191,7 +191,7 @@ public CultureInfo UICulture { if (value == null) { - throw new ArgumentNullException("value"); + throw new ArgumentNullException(nameof(value)); } _uiCulture = value; @@ -400,7 +400,7 @@ public Uri ConnectionUri { if (value == null) { - throw PSTraceSource.NewArgumentNullException("value"); + throw PSTraceSource.NewArgumentNullException(nameof(value)); } UpdateUri(value); @@ -604,7 +604,7 @@ public override string CertificateThumbprint { if (value == null) { - throw PSTraceSource.NewArgumentNullException("value"); + throw PSTraceSource.NewArgumentNullException(nameof(value)); } _thumbPrint = value; diff --git a/src/System.Management.Automation/engine/remoting/fanin/OutOfProcTransportManager.cs b/src/System.Management.Automation/engine/remoting/fanin/OutOfProcTransportManager.cs index bc39b8f6937..a1d234b1a23 100644 --- a/src/System.Management.Automation/engine/remoting/fanin/OutOfProcTransportManager.cs +++ b/src/System.Management.Automation/engine/remoting/fanin/OutOfProcTransportManager.cs @@ -1590,7 +1590,7 @@ internal SSHClientSessionTransportManager( PSRemotingCryptoHelper cryptoHelper) : base(runspaceId, cryptoHelper) { - if (connectionInfo == null) { throw new PSArgumentException("connectionInfo"); } + if (connectionInfo == null) { throw new PSArgumentNullException(nameof(connectionInfo)); } _connectionInfo = connectionInfo; } diff --git a/src/System.Management.Automation/engine/runtime/MutableTuple.cs b/src/System.Management.Automation/engine/runtime/MutableTuple.cs index de923e2df8b..ba5e8b245c6 100644 --- a/src/System.Management.Automation/engine/runtime/MutableTuple.cs +++ b/src/System.Management.Automation/engine/runtime/MutableTuple.cs @@ -364,7 +364,7 @@ internal static IEnumerable GetAccessProperties(Type tupleType, in { // ContractUtils.RequiresNotNull(tupleType, "tupleType"); - if (index < 0 || index >= size) throw new ArgumentException("index"); + if (index < 0 || index >= size) throw new ArgumentException(null, nameof(index)); foreach (int curIndex in GetAccessPath(size, index)) { diff --git a/src/System.Management.Automation/engine/serialization.cs b/src/System.Management.Automation/engine/serialization.cs index b70c7037c26..dce40312101 100644 --- a/src/System.Management.Automation/engine/serialization.cs +++ b/src/System.Management.Automation/engine/serialization.cs @@ -64,7 +64,7 @@ internal SerializationContext(int depth, SerializationOptions options, PSRemotin { if (depth < 1) { - throw PSTraceSource.NewArgumentException("writer", Serialization.DepthOfOneRequired); + throw PSTraceSource.NewArgumentException(nameof(depth), Serialization.DepthOfOneRequired); } this.depth = depth; @@ -7526,7 +7526,7 @@ private static PSControl RehydratePSControl(PSObject deserializedControl) } else { - throw PSTraceSource.NewArgumentException("pso"); + throw PSTraceSource.NewArgumentException(nameof(deserializedControl)); } result.GroupBy = GetPropertyValue(deserializedControl, "GroupBy", RehydrationFlags.MissingPropertyOk); diff --git a/src/System.Management.Automation/help/HelpErrorTracer.cs b/src/System.Management.Automation/help/HelpErrorTracer.cs index 9c9fd0165b5..f22ea927494 100644 --- a/src/System.Management.Automation/help/HelpErrorTracer.cs +++ b/src/System.Management.Automation/help/HelpErrorTracer.cs @@ -124,7 +124,7 @@ internal HelpErrorTracer(HelpSystem helpSystem) { if (helpSystem == null) { - throw PSTraceSource.NewArgumentNullException("HelpSystem"); + throw PSTraceSource.NewArgumentNullException(nameof(helpSystem)); } HelpSystem = helpSystem; diff --git a/src/System.Management.Automation/help/HelpSystem.cs b/src/System.Management.Automation/help/HelpSystem.cs index fb92ed1c19c..94e26f2e3e2 100644 --- a/src/System.Management.Automation/help/HelpSystem.cs +++ b/src/System.Management.Automation/help/HelpSystem.cs @@ -95,7 +95,7 @@ internal HelpSystem(ExecutionContext context) { if (context == null) { - throw PSTraceSource.NewArgumentNullException("ExecutionContext"); + throw PSTraceSource.NewArgumentNullException(nameof(context)); } _executionContext = context; diff --git a/src/System.Management.Automation/namespaces/CoreCommandContext.cs b/src/System.Management.Automation/namespaces/CoreCommandContext.cs index 34cdb0d68b7..c7a50525542 100644 --- a/src/System.Management.Automation/namespaces/CoreCommandContext.cs +++ b/src/System.Management.Automation/namespaces/CoreCommandContext.cs @@ -133,12 +133,12 @@ internal CmdletProviderContext( if (command.Host == null) { - throw PSTraceSource.NewArgumentException("command.Host"); + throw PSTraceSource.NewArgumentException(nameof(command), "command.Host is null"); } if (command.Context == null) { - throw PSTraceSource.NewArgumentException("command.Context"); + throw PSTraceSource.NewArgumentException(nameof(command), "command.Context is null"); } ExecutionContext = command.Context; @@ -185,12 +185,12 @@ internal CmdletProviderContext( if (command.Host == null) { - throw PSTraceSource.NewArgumentException("command.Host"); + throw PSTraceSource.NewArgumentException(nameof(command), "command.Host is null"); } if (command.Context == null) { - throw PSTraceSource.NewArgumentException("command.Context"); + throw PSTraceSource.NewArgumentException(nameof(command), "command.Context is null"); } ExecutionContext = command.Context; @@ -228,7 +228,7 @@ internal CmdletProviderContext( if (command.Context == null) { - throw PSTraceSource.NewArgumentException("command.Context"); + throw PSTraceSource.NewArgumentException(nameof(command), "command.Context is null"); } ExecutionContext = command.Context; diff --git a/src/System.Management.Automation/namespaces/FileSystemProvider.cs b/src/System.Management.Automation/namespaces/FileSystemProvider.cs index 9c454ce68f9..0ca7e3e0fd2 100644 --- a/src/System.Management.Automation/namespaces/FileSystemProvider.cs +++ b/src/System.Management.Automation/namespaces/FileSystemProvider.cs @@ -513,7 +513,7 @@ protected override PSDriveInfo NewDrive(PSDriveInfo drive) if (string.IsNullOrEmpty(drive.Root)) { - throw PSTraceSource.NewArgumentException("drive.Root"); + throw PSTraceSource.NewArgumentException(nameof(drive), "drive.Root is null or empty"); } // -Persist switch parameter is supported only for Network paths. @@ -6646,7 +6646,7 @@ public IContentReader GetContentReader(string path) if (usingByteEncoding) { Exception e = - new ArgumentException(FileSystemProviderStrings.DelimiterError, "delimiter"); + new ArgumentException(FileSystemProviderStrings.DelimiterError); WriteError(new ErrorRecord( e, "GetContentReaderArgumentError", diff --git a/src/System.Management.Automation/namespaces/ProviderBase.cs b/src/System.Management.Automation/namespaces/ProviderBase.cs index 326d4d51b04..30989bb32f4 100644 --- a/src/System.Management.Automation/namespaces/ProviderBase.cs +++ b/src/System.Management.Automation/namespaces/ProviderBase.cs @@ -138,7 +138,7 @@ internal CmdletProviderContext Context { if (value == null) { - throw PSTraceSource.NewArgumentNullException("value"); + throw PSTraceSource.NewArgumentNullException(nameof(value)); } // Check that the provider supports the use of credentials diff --git a/src/System.Management.Automation/namespaces/SessionStateProviderBase.cs b/src/System.Management.Automation/namespaces/SessionStateProviderBase.cs index 33b043ce919..bf3b9d45137 100644 --- a/src/System.Management.Automation/namespaces/SessionStateProviderBase.cs +++ b/src/System.Management.Automation/namespaces/SessionStateProviderBase.cs @@ -694,7 +694,7 @@ protected override void NewItem(string path, string type, object newItem) if (newItem == null) { ArgumentNullException argException = - PSTraceSource.NewArgumentNullException("value"); + PSTraceSource.NewArgumentNullException(nameof(newItem)); WriteError( new ErrorRecord( diff --git a/src/System.Management.Automation/security/CredentialParameter.cs b/src/System.Management.Automation/security/CredentialParameter.cs index 0d48e4fa738..ff1b6eb5c30 100644 --- a/src/System.Management.Automation/security/CredentialParameter.cs +++ b/src/System.Management.Automation/security/CredentialParameter.cs @@ -59,7 +59,7 @@ public override object Transform(EngineIntrinsics engineIntrinsics, object input // throw an exception if (userName == null) { - throw new PSArgumentException("userName"); + throw new PSArgumentException(nameof(inputData), "userName is null"); } } } diff --git a/src/System.Management.Automation/security/SecurityManager.cs b/src/System.Management.Automation/security/SecurityManager.cs index f6ae0fdf1f3..cb112a59ff5 100644 --- a/src/System.Management.Automation/security/SecurityManager.cs +++ b/src/System.Management.Automation/security/SecurityManager.cs @@ -613,7 +613,7 @@ protected internal override bool ShouldRun(CommandInfo commandInfo, ExternalScriptInfo si = commandInfo as ExternalScriptInfo; if (si == null) { - reason = PSTraceSource.NewArgumentException("scriptInfo"); + reason = PSTraceSource.NewArgumentException(nameof(commandInfo), "commandInfo is not of type ExternalScriptInfo"); } else { diff --git a/src/System.Management.Automation/utils/EncodingUtils.cs b/src/System.Management.Automation/utils/EncodingUtils.cs index 8206b5cf8a3..00c01f75497 100644 --- a/src/System.Management.Automation/utils/EncodingUtils.cs +++ b/src/System.Management.Automation/utils/EncodingUtils.cs @@ -71,7 +71,7 @@ internal static Encoding Convert(Cmdlet cmdlet, string encoding) string msg = StringUtil.Format(PathUtilsStrings.OutFile_WriteToFileEncodingUnknown, encoding, validEncodingValues); ErrorRecord errorRecord = new ErrorRecord( - PSTraceSource.NewArgumentException("Encoding"), + PSTraceSource.NewArgumentException(nameof(encoding)), "WriteToFileEncodingUnknown", ErrorCategory.InvalidArgument, null); diff --git a/src/System.Management.Automation/utils/MshTraceSource.cs b/src/System.Management.Automation/utils/MshTraceSource.cs index 9bb0cfbcc3d..3f685417c32 100644 --- a/src/System.Management.Automation/utils/MshTraceSource.cs +++ b/src/System.Management.Automation/utils/MshTraceSource.cs @@ -187,7 +187,7 @@ internal static PSTraceSource GetNewTraceSource( // Note, all callers should have already verified the name before calling this // API, so this exception should never be exposed to an end-user. - throw new ArgumentException("name"); + throw new ArgumentException(null, nameof(name)); } // Keep the fullName as it was passed, but truncate or pad