diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/AddMember.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/AddMember.cs index ca2aa30235..e645fe871f 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/AddMember.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/AddMember.cs @@ -514,7 +514,7 @@ namespace Microsoft.PowerShell.Commands private ErrorRecord NewError(string errorId, string resourceId, object targetObject, params object[] args) { ErrorDetails details = new ErrorDetails(this.GetType().GetTypeInfo().Assembly, - "AddMember", resourceId, args); + "Microsoft.PowerShell.Commands.Utility.resources.AddMember", resourceId, args); ErrorRecord errorRecord = new ErrorRecord( new InvalidOperationException(details.Message), errorId, diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/ConvertToJsonCommand.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/ConvertToJsonCommand.cs index 4def219c2c..5c1e1f1421 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/ConvertToJsonCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/ConvertToJsonCommand.cs @@ -381,10 +381,8 @@ namespace Microsoft.PowerShell.Commands private ErrorRecord NewError() { - ErrorDetails details = new ErrorDetails(this.GetType().GetTypeInfo().Assembly, - "WebCmdletStrings", "JsonStringInBadFormat"); ErrorRecord errorRecord = new ErrorRecord( - new InvalidOperationException(details.Message), + new InvalidOperationException(WebCmdletStrings.JsonStringInBadFormat), "JsonStringInBadFormat", ErrorCategory.InvalidOperation, InputObject); diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Add-Member.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Add-Member.Tests.ps1 index eb855cda04..54634705e0 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Add-Member.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Add-Member.Tests.ps1 @@ -276,6 +276,14 @@ $results = add-member -InputObject a 16 sp {1+1} -passthru $results.sp | Should Be 2 } + + It "Verify Add-Member error message is not empty" { + $object = @(1,2) + Add-Member -InputObject $object "ABC" "Value1" + Add-Member -InputObject $object "ABC" "Value2" -ErrorVariable errorVar -ErrorAction SilentlyContinue + $errorVar.Exception | Should BeOfType "System.InvalidOperationException" + $errorVar.Exception.Message | Should Not BeNullOrEmpty + } } Describe "Add-Member" -Tags "CI" {