Skip to content

(PS 7.0 preview) Powershell Integrated Console launches in different apartment state vs using "new terminal" #2216

Open
@TheManii

Description

@TheManii

Issue Description

I am not able to run my existing WPF + PS based code while specifically in the integrated console due to the fact that the integrated console runs in MTA. The same code does work fine either in a normal, standalone session (which I mean as launching PWSH.exe from the run dialog/similar) of PS 7 or in a standard (non integrated console) session of PWSH in VSC. Standalone sessions and standard sessions in VSC run under STA.

Background

Powershell 7.0 preview 3 (re) added STA as an available apartment state and also set it back to being the default apartment state.

STA is needed to run WPF and WinForm code as they will only run under STA. Previously PS Core removed STA as an option because there was no need to run under anything besides MTA as WPF/WF were no longer supported, but 7.0 preview 3 defaulted back to STA as a feature point to implicitly support WPF/WF.

Attached Logs

Steps to reproduce:
0. Set Powershell 7 as the default session
1a. Launch the integrated console
2a. run [System.Threading.Thread]::CurrentThread.GetApartmentState()
3a. Output is: MTA

1b. Launch a "normal"/standalone pwsh session
2b. run [System.Threading.Thread]::CurrentThread.GetApartmentState()
3b. Output is: STA

Expected Results for step 3a:
Either the output is also STA or an option to use STA by default

Environment Information

Visual Studio Code

Name Version
Operating System Windows_NT x64 10.0.18362
VSCode 1.38.1
PowerShell Extension Version 2019.9.0

PowerShell Information

Name Value
PSVersion 7.0.0-preview.4
PSEdition Core
GitCommitId 7.0.0-preview.4
OS Microsoft Windows 10.0.18362
Platform Win32NT
PSCompatibleVersions 1.0 2.0 3.0 4.0 5.0 5.1.10032.0 6.0.0 6.1.0 6.2.0 7.0.0-preview.4
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0

Visual Studio Code Extensions

Visual Studio Code Extensions(Click to Expand)
Extension Author Version
code-spell-checker streetsidesoftware 1.7.17
cpptools ms-vscode 0.24.1
csharp ms-vscode 1.21.3
docs-markdown docsmsft 0.2.13
githistory donjayamanne 0.4.6
java redhat 0.47.0
powershell ms-vscode 2019.9.0
remote-wsl ms-vscode-remote 0.38.10
vscode-java-debug vscjava 0.20.0
vscode-java-dependency vscjava 0.5.1
vscode-java-pack vscjava 0.7.1
vscode-java-test vscjava 0.19.0
vscode-maven vscjava 0.18.1
vscodeintellicode VisualStudioExptTeam 1.1.9

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions