Skip to content

Runspace with SSHConnectionInfo is not working on Linux or Windows #15641

@stwolfe

Description

@stwolfe

Steps to reproduce

Create a simple program

using System;
using System.Management.Automation;
using System.Management.Automation.Remoting;
using System.Management.Automation.Runspaces;

namespace util
{
    class Program
    {
        static void Main(string[] args)
        {
            var connectionInfo = new SSHConnectionInfo("username", "machinename", null, port: 22)
            {
            };

            var runspace = RunspaceFactory.CreateRunspace(connectionInfo);
            runspace.Open();

            System.Console.WriteLine("Hit any key to exit...");
            System.Console.ReadKey();
        }
    }
}

Try to run:

dotnet run

Expected behavior

Successful run.

Actual behavior


PS > dotnet run
Unhandled exception. System.Management.Automation.Remoting.PSRemotingDataStructureException: An error has occurred which PowerShell cannot handle. A remote session might have ended.
 ---> System.ComponentModel.Win32Exception (2): No such file or directory
   at System.Management.Automation.Runspaces.SSHConnectionInfo.CreateProcess(String filename, String[] argv, String[] envp, String cwd, Boolean redirectStdin, Boolean redirectStdout, Boolean redirectStderr, Int32 creationFlags, Int32& lpChildPid, Int32& stdinFd, Int32& stdoutFd, Int32& stderrFd)
   at System.Management.Automation.Runspaces.SSHConnectionInfo.StartSSHProcess(ProcessStartInfo startInfo, StreamWriter& standardInput, StreamReader& standardOutput, StreamReader& standardError)
   at System.Management.Automation.Runspaces.SSHConnectionInfo.StartSSHProcessImpl(ProcessStartInfo startInfo, StreamWriter& stdInWriterVar, StreamReader& stdOutReaderVar, StreamReader& stdErrReaderVar)
   at System.Management.Automation.Runspaces.SSHConnectionInfo.StartSSHProcess(StreamWriter& stdInWriterVar, StreamReader& stdOutReaderVar, StreamReader& stdErrReaderVar)
   at System.Management.Automation.Remoting.Client.SSHClientSessionTransportManager.CreateAsync()
   at System.Management.Automation.Remoting.ClientRemoteSessionDSHandlerImpl.SendNegotiationAsync(RemoteSessionState sessionState)
   at System.Management.Automation.Remoting.ClientRemoteSessionDSHandlerImpl.HandleStateChanged(Object sender, RemoteSessionStateEventArgs arg)
   at System.Management.Automation.ExtensionMethods.SafeInvoke[T](EventHandler`1 eventHandler, Object sender, T eventArgs)
   at System.Management.Automation.Remoting.ClientRemoteSessionDSHandlerStateMachine.RaiseStateMachineEvents()
   at System.Management.Automation.Remoting.ClientRemoteSessionDSHandlerStateMachine.ProcessEvents()
   --- End of inner exception stack trace ---
   at System.Management.Automation.Runspaces.AsyncResult.EndInvoke()
   at System.Management.Automation.Runspaces.Internal.RunspacePoolInternal.EndOpen(IAsyncResult asyncResult)
   at System.Management.Automation.Runspaces.Internal.RemoteRunspacePoolInternal.Open()
   at System.Management.Automation.Runspaces.RunspacePool.Open()
   at System.Management.Automation.RemoteRunspace.Open()
   at util.Program.Main(String[] args) in /mnt/c/work/util/Program.cs:line 17


Environment data

Linux

PS > $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.1.3
PSEdition                      Core
GitCommitId                    7.1.3
OS                             Linux 4.19.104-microsoft-standard #1 SMP Wed Feb 19 06:37:35 UTC 2020
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-BugIssue has been identified as a bug in the productWG-RemotingPSRP issues with any transport layer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions