-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Closed
Labels
Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-AnsweredThe question is answered.The question is answered.
Description
This is to discuss and potentially document current behaviour (that is inconsistent with Windows PowerShell). Maybe some porting work was forgotten since the APIs were initially not available in .Net Core 1.
When creating a new PowerShell instance using [Management.Automation.PowerShell]::Create() (or when creating a new runspace using [runspacefactory]::CreateRunspace()), then PowerShell Core and Windows PowerShell are both in MTA mode. This seems to be reasonable.
When being in the shell of PowerShell Core, the default ApartmentState is also MTA, which seems OK as well at first.
However, Windows PowerShell is in STA mode by default and powershell.exe even has an MTA and STA switch, which PowerShell Core does not have.
My questions:
- Why was
STAchosen to be the default when being in a shell or ConsoleHost of Windows PowerShell? If there was a reason, we should reconsider it for PowerShell Core. I should add though that this inconsistency could lead to a situation that is difficult to debug (we had a case where execution in the shell was fine but when using our PowerShell runner that uses the PowerShell APIs, we were experiencing threading issues and scratching our heads for some time what the reason could be until we found out about the inconsistency in Windows PowerShell) - Does
pwshneed anSTAcommand line option? In our case we can workaround it by setting it ourselves by setting it in theInitialSessionStatethat we then pass toPowerShell.Create()
Metadata
Metadata
Assignees
Labels
Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-AnsweredThe question is answered.The question is answered.