From e299a301281e3629ad956f39166c0e0c79b1e0d1 Mon Sep 17 00:00:00 2001 From: Dongbo Wang Date: Mon, 8 Apr 2019 11:06:27 -0700 Subject: [PATCH] Fixing test run crash by not passing script block to the callback (#9298) --- .../engine/hostifaces/PowerShell.cs | 18 ++++++++++++++++++ .../Api/TaskBasedAsyncPowerShellAPI.Tests.ps1 | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/System.Management.Automation/engine/hostifaces/PowerShell.cs b/src/System.Management.Automation/engine/hostifaces/PowerShell.cs index 2014d3d5cb..a2ec055764 100644 --- a/src/System.Management.Automation/engine/hostifaces/PowerShell.cs +++ b/src/System.Management.Automation/engine/hostifaces/PowerShell.cs @@ -2915,6 +2915,9 @@ namespace System.Management.Automation /// /// /// An AsyncCallback to call once the BeginInvoke completes. + /// Note: when using this API in script, don't pass in a delegate that is cast from a script block. + /// The callback could be invoked from a thread without a default Runspace and a delegate cast from + /// a script block would fail in that case. /// /// /// A user supplied state to call the @@ -3036,6 +3039,9 @@ namespace System.Management.Automation /// /// /// An AsyncCallback to call once the BeginInvoke completes. + /// Note: when using this API in script, don't pass in a delegate that is cast from a script block. + /// The callback could be invoked from a thread without a default Runspace and a delegate cast from + /// a script block would fail in that case. /// /// /// A user supplied state to call the @@ -3158,6 +3164,9 @@ namespace System.Management.Automation /// /// /// An AsyncCallback to call once the command is invoked. + /// Note: when using this API in script, don't pass in a delegate that is cast from a script block. + /// The callback could be invoked from a thread without a default Runspace and a delegate cast from + /// a script block would fail in that case. /// /// /// A user supplied state to call the @@ -3264,6 +3273,9 @@ namespace System.Management.Automation /// /// /// An AsyncCallback to call once the command is invoked. + /// Note: when using this API in script, don't pass in a delegate that is cast from a script block. + /// The callback could be invoked from a thread without a default Runspace and a delegate cast from + /// a script block would fail in that case. /// /// /// A user supplied state to call the @@ -3733,6 +3745,9 @@ namespace System.Management.Automation /// /// /// A AsyncCallback to call once the BeginStop completes. + /// Note: when using this API in script, don't pass in a delegate that is cast from a script block. + /// The callback could be invoked from a thread without a default Runspace and a delegate cast from + /// a script block would fail in that case. /// /// /// A user supplied state to call the @@ -3794,6 +3809,9 @@ namespace System.Management.Automation /// /// /// An AsyncCallback to call once the command is invoked. + /// Note: when using this API in script, don't pass in a delegate that is cast from a script block. + /// The callback could be invoked from a thread without a default Runspace and a delegate cast from + /// a script block would fail in that case. /// /// /// A user supplied state to call the diff --git a/test/powershell/engine/Api/TaskBasedAsyncPowerShellAPI.Tests.ps1 b/test/powershell/engine/Api/TaskBasedAsyncPowerShellAPI.Tests.ps1 index 8130eade2a..64b1221694 100644 --- a/test/powershell/engine/Api/TaskBasedAsyncPowerShellAPI.Tests.ps1 +++ b/test/powershell/engine/Api/TaskBasedAsyncPowerShellAPI.Tests.ps1 @@ -207,7 +207,7 @@ try { try { $ir = $ps.AddScript("Start-Sleep -Seconds 60").InvokeAsync() Wait-UntilTrue { $ps.InvocationStateInfo.State -eq [System.Management.Automation.PSInvocationState]::Running } - $sr = $ps.StopAsync({}, $null) + $sr = $ps.StopAsync($null, $null) [System.Threading.Tasks.Task]::WaitAll(@($sr)) $sr.IsCompletedSuccessfully | Should -Be $true $ir.IsFaulted | Should -Be $true