Skip to content

.NET SDK's InvokeAsync hangs forever when command contains multiple statements #26594

@oleksandr-andrusenko

Description

@oleksandr-andrusenko

Prerequisites

Steps to reproduce

Minimal reproducible example for .NET 9 with Microsoft.PowerShell.SDK 7.5.4:

using var pool = RunspaceFactory.CreateRunspacePool(CreateSessionState());
pool.SetMinRunspaces(1);
pool.SetMaxRunspaces(5);
pool.Open();

using var ps = PowerShell.Create();
ps.RunspacePool = pool;

ps.AddScript("Write-Output");
ps.AddStatement();
ps.AddScript("Write-Output");

var result = await ps.InvokeAsync();

Based on the documentation for the InvokeAsync method with no arguments, it doesn't require any setup and should work fine. In fact, if there's only one statement, it works just fine.

Interestingly, the synchronous Invoke method doesn't have any problems with multiple statements and works as expected.

Expected behavior

I would expect it to work similarly to the synchronous `Invoke()` method.

Actual behavior

The call to `InvokeAsync` hangs forever.

Error details

There are no errors.

Environment data

Name                           Value
----                           -----
PSVersion                      7.5.4
PSEdition                      Core
GitCommitId                    7.5.4
OS                             Ubuntu 24.04.1 LTS
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs-TriageThe issue is new and needs to be triaged by a work group.WG-NeedsReviewNeeds a review by the labeled Working GroupWG-RemotingPSRP issues with any transport layer

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions