The output of Write-Error is ommited in methods that have a return value (i.e. are not void):
Class MyClass {
[void]MethodWithoutReturnValue([string]$Msg) {
Write-Error "MyClass.MethodWithoutReturnValue(): $Msg"
}
[bool]MethodWithReturnValue([string]$Msg) {
Write-Error "MyClass.MethodWithReturnValue(): $Msg"
$this.MethodWithoutReturnValue("this won't work either")
return $true
}
}
[MyClass]$obj = [MyClass]::new()
$obj.MethodWithoutReturnValue('this error will show up')
[bool]$Result = $obj.MethodWithReturnValue('this error will NOT show up')
I'm expecting three error message but only get one. Please notice that the calling the void method from the bool method also omits the output, as if the call stack is "poisoned" somehow. And yes (though not shown in this example) void method calling void method works.
Can someone please explain this behaviour or did I just find a bug?