Skip to content

Commit e299a30

Browse files
daxian-dbwadityapatwardhan
authored andcommitted
Fixing test run crash by not passing script block to the callback (PowerShell#9298)
1 parent 98b2e14 commit e299a30

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/System.Management.Automation/engine/hostifaces/PowerShell.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2915,6 +2915,9 @@ public IAsyncResult BeginInvoke<T>(PSDataCollection<T> input)
29152915
/// </param>
29162916
/// <param name="callback">
29172917
/// An AsyncCallback to call once the BeginInvoke completes.
2918+
/// Note: when using this API in script, don't pass in a delegate that is cast from a script block.
2919+
/// The callback could be invoked from a thread without a default Runspace and a delegate cast from
2920+
/// a script block would fail in that case.
29182921
/// </param>
29192922
/// <param name="state">
29202923
/// A user supplied state to call the <paramref name="callback"/>
@@ -3036,6 +3039,9 @@ public IAsyncResult BeginInvoke<TInput, TOutput>(PSDataCollection<TInput> input,
30363039
/// </param>
30373040
/// <param name="callback">
30383041
/// An AsyncCallback to call once the BeginInvoke completes.
3042+
/// Note: when using this API in script, don't pass in a delegate that is cast from a script block.
3043+
/// The callback could be invoked from a thread without a default Runspace and a delegate cast from
3044+
/// a script block would fail in that case.
30393045
/// </param>
30403046
/// <param name="state">
30413047
/// A user supplied state to call the <paramref name="callback"/>
@@ -3158,6 +3164,9 @@ public Task<PSDataCollection<PSObject>> InvokeAsync<T>(PSDataCollection<T> input
31583164
/// </param>
31593165
/// <param name="callback">
31603166
/// An AsyncCallback to call once the command is invoked.
3167+
/// Note: when using this API in script, don't pass in a delegate that is cast from a script block.
3168+
/// The callback could be invoked from a thread without a default Runspace and a delegate cast from
3169+
/// a script block would fail in that case.
31613170
/// </param>
31623171
/// <param name="state">
31633172
/// A user supplied state to call the <paramref name="callback"/>
@@ -3264,6 +3273,9 @@ public Task<PSDataCollection<PSObject>> InvokeAsync<TInput, TOutput>(PSDataColle
32643273
/// </param>
32653274
/// <param name="callback">
32663275
/// An AsyncCallback to call once the command is invoked.
3276+
/// Note: when using this API in script, don't pass in a delegate that is cast from a script block.
3277+
/// The callback could be invoked from a thread without a default Runspace and a delegate cast from
3278+
/// a script block would fail in that case.
32673279
/// </param>
32683280
/// <param name="state">
32693281
/// A user supplied state to call the <paramref name="callback"/>
@@ -3733,6 +3745,9 @@ public void Stop()
37333745
/// </summary>
37343746
/// <param name="callback">
37353747
/// A AsyncCallback to call once the BeginStop completes.
3748+
/// Note: when using this API in script, don't pass in a delegate that is cast from a script block.
3749+
/// The callback could be invoked from a thread without a default Runspace and a delegate cast from
3750+
/// a script block would fail in that case.
37363751
/// </param>
37373752
/// <param name="state">
37383753
/// A user supplied state to call the <paramref name="callback"/>
@@ -3794,6 +3809,9 @@ public void EndStop(IAsyncResult asyncResult)
37943809
/// </remarks>
37953810
/// <param name="callback">
37963811
/// An AsyncCallback to call once the command is invoked.
3812+
/// Note: when using this API in script, don't pass in a delegate that is cast from a script block.
3813+
/// The callback could be invoked from a thread without a default Runspace and a delegate cast from
3814+
/// a script block would fail in that case.
37973815
/// </param>
37983816
/// <param name="state">
37993817
/// A user supplied state to call the <paramref name="callback"/>

test/powershell/engine/Api/TaskBasedAsyncPowerShellAPI.Tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ try {
207207
try {
208208
$ir = $ps.AddScript("Start-Sleep -Seconds 60").InvokeAsync()
209209
Wait-UntilTrue { $ps.InvocationStateInfo.State -eq [System.Management.Automation.PSInvocationState]::Running }
210-
$sr = $ps.StopAsync({}, $null)
210+
$sr = $ps.StopAsync($null, $null)
211211
[System.Threading.Tasks.Task]::WaitAll(@($sr))
212212
$sr.IsCompletedSuccessfully | Should -Be $true
213213
$ir.IsFaulted | Should -Be $true

0 commit comments

Comments
 (0)