Skip to content

Jobs do not work in hosted PowerShell Core #7052

Closed

Description

It appears that trying to run jobs inside hosted PowerShell Core from a .NET Core 2.0 app fails.
This was first noticed in Jaykul/Jupyter-PowerShell#20 But I was able to coble together a simple repro https://github.com/markekraus/TesthostedPSJobs

Joel Bennett (@Jaykul) suggested I try and copy the pwsh binary to the hosted app location, but that doesn't seem to work either.

Steps to reproduce

git clone https://github.com/markekraus/TesthostedPSJobs.git
push-location TesthostedPSJobs
dotnet run

Expected behavior

No output

Actual behavior

Error: [localhost] An error occurred while starting the background process. Error reported: The system cannot find the file specified.
Exception: System.Management.Automation.Remoting.PSRemotingTransportException: An error occurred while starting the background process. Error reported: The system cannot find the file specified. ---> System.ComponentModel.Win32Exception: The system cannot find the file specified
   at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
   at System.Diagnostics.Process.Start()
   at System.Management.Automation.Runspaces.PowerShellProcessInstance.Start()
   at System.Management.Automation.Remoting.Client.OutOfProcessClientSessionTransportManager.CreateAsync()
   --- End of inner exception stack trace ---
InnerException: System.ComponentModel.Win32Exception (0x80004005): The system cannot find the file specified
   at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
   at System.Diagnostics.Process.Start()
   at System.Management.Automation.Runspaces.PowerShellProcessInstance.Start()
   at System.Management.Automation.Remoting.Client.OutOfProcessClientSessionTransportManager.CreateAsync()
InnerException:
--------------------------------------------------------

Environment data

Windows 10 x64 (I have not verified this on other OSes)
6.0.2

Activity

  1. added
    Issue-Discussion
    on Jun 13, 2018
  2. BrucePay commented on Jun 13, 2018

    @BrucePay
    Collaborator

    Mark Kraus (@markekraus) Start-Job looks for pwsh.exe using typeof(PSObject).Assembly.Location. Basically it expects to find pwsh.exe in the same directory as System.Management.Automation.dll. Perhaps we need an alternate mechanism for looking up what executable to launch.

  3. markekraus commented on Jun 13, 2018

    @markekraus
    ContributorAuthor

    Bruce Payette (@BrucePay) After copying the pwsh.exe to the publish folder

    Error: [localhost] The background process reported an error with the following message: .
    Exception: System.Management.Automation.Remoting.PSRemotingTransportException: The background process reported an error with the following message: .
    InnerException:
    
    Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
       at TesthostedPSJobs.Program.Main(String[] args) in C:\Git\TesthostedPSJobs\Program.cs:line 18
    

    Looking at this from a self contain app, how would you ship this and make it work?

    edit: it looks like if I take the exe and dll from my project and drop it in the PowerShell install folder... it works... but that is a really odd way to go about shipping a hosted app that supports jobs...

  4. BrucePay commented on Jun 13, 2018

    @BrucePay
    Collaborator

    Rather than copying stuff into the applications directory. I'd suggest that we have a more flexible way of finding pwsh.exe like using an environment variable or a configuration file (or the path?). Even within PowerShell Core itself, we should be able to start Windows PowerShell jobs from PowerShell Core but currently we can't because of the hard-coding (see #7059)

  5. added
    WG-Engine
    and removed on Jun 13, 2018
  6. markekraus commented on Jun 14, 2018

    @markekraus
    ContributorAuthor

    Bruce Payette (@BrucePay) But if we used pwsh.exe from the path.. that would mean when I build my app it would include the .NET Core and PS libraries... and then I would also need to ship the entire pwsh with it.. which would also include all the .NET Core and PS libraries. basically, to have jobs working in hosted PowerShell Core I would need to double up on PowerShell libraries.

    Unlike .NET Framework, in .NET Core when you publish an app all the DLLs for the framework and PowerShell go with it.

  7. daxian-dbw commented on Nov 15, 2021

    @daxian-dbw
    Member

    The PowerShell Job requires pwsh to be installed, and thus it doesn't work for an application that hosts PowerShell. The recommendation is to use ThreadJob instead.

  8. added
    Resolution-By Design
    and removed
    Issue-Discussion
    on Nov 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Resolution-By DesignWG-Engine

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions