diff --git a/src/PowerShellEditorServices/Services/PowerShell/Utility/ErrorRecordExtensions.cs b/src/PowerShellEditorServices/Services/PowerShell/Utility/ErrorRecordExtensions.cs index 031a24749..41721dc12 100644 --- a/src/PowerShellEditorServices/Services/PowerShell/Utility/ErrorRecordExtensions.cs +++ b/src/PowerShellEditorServices/Services/PowerShell/Utility/ErrorRecordExtensions.cs @@ -34,7 +34,7 @@ static ErrorRecordExtensions() s_setWriteStreamProperty = Expression.Lambda>( Expression.Call( errorObjectParameter, - writeStreamProperty.GetSetMethod(), + writeStreamProperty.GetSetMethod(nonPublic: true), Expression.Constant(errorStreamType)), errorObjectParameter) .Compile(); diff --git a/src/PowerShellEditorServices/Utility/PSCommandExtensions.cs b/src/PowerShellEditorServices/Utility/PSCommandExtensions.cs index 602937db2..9921f577d 100644 --- a/src/PowerShellEditorServices/Utility/PSCommandExtensions.cs +++ b/src/PowerShellEditorServices/Utility/PSCommandExtensions.cs @@ -55,10 +55,13 @@ public static PSCommand AddDebugOutputCommand(this PSCommand psCommand) public static PSCommand MergePipelineResults(this PSCommand psCommand) { - // We need to do merge errors and output before rendering with an Out- cmdlet - Command lastCommand = psCommand.Commands[psCommand.Commands.Count - 1]; - lastCommand.MergeMyResults(PipelineResultTypes.Error, PipelineResultTypes.Output); - lastCommand.MergeMyResults(PipelineResultTypes.Information, PipelineResultTypes.Output); + if (psCommand.Commands.Count > 0) + { + // We need to do merge errors and output before rendering with an Out- cmdlet + Command lastCommand = psCommand.Commands[psCommand.Commands.Count - 1]; + lastCommand.MergeMyResults(PipelineResultTypes.Error, PipelineResultTypes.Output); + lastCommand.MergeMyResults(PipelineResultTypes.Information, PipelineResultTypes.Output); + } return psCommand; }