Vscode-powershell: The language service could not be started (PowerShell Global Tool)

Created on 8 Apr 2020  路  13Comments  路  Source: PowerShell/vscode-powershell

System Details

System Details Output

PS C:\Users\Pascal Ried> & {"### VSCode version: $(code -v)"; "`n### VSCode extensions:`n$(code --list-extensions --show-versions | Out-String)"; "`n### PSES version: $($pseditor.EditorServicesVersion)"; "`n### PowerShell version:`n$($PSVersionTable | Out-String)"}

### VSCode version: 1.44.0 2aae1f26c72891c399f860409176fe435a154b13 x64

### VSCode extensions:
[email protected]  
[email protected]        
[email protected]
[email protected]      
[email protected]   
[email protected]       
[email protected]
[email protected]  
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]


### PSES version: 2.0.0.0

### PowerShell version:

Name                           Value
----                           -----
PSVersion                      7.0.0
PSEdition                      Core
GitCommitId                    7.0.0
OS                             Microsoft Windows 10.0.18362
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0鈥
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Issue Description

Same problem as for #2119 and #1360 and #1957 and others.

Don't know when it started but PowerShell failed to work for me and doing what's said in issue #2119 did not help. I've fixed the problem now manually with changes to settings.json (see below my workaround). I wanted to share my solution here.

Problem: "The language service could not be started" and no support for PS in VS Code.
Additionally, every time I start VS this red message appears very shortly (like for half a second) in a terminal inside VSC (in German):
image

Get-ExecutionPolicy is set to Bypass (no difference when setting it to Default, either).

Executing suggested Import-Module $HOME\.vscode\extensions\ms-vscode.powershell*\modules\PowerShellEditorServices\PowerShellEditorServices.psd1 does nothing (no question, no output, nothing).

I've now installed PS7 (.NET Core version), thinking maybe it fixes the problem - doesn't fix it.
Trying the same command (Import-Module...) with PS7 - nothing different.

When using >PowerShell: Show Session Menu I see the following:
image

I then select Switch to: Windows PowerShell (x64) and that seems to fix my problem as now the mentioned question about the "untrustworthy code" shows up and after saying [A] to it, everything works as expected.

Only problem now, PS7 is not used but I really want to use the new PS7.
The "Session Menu" now shows:
image

I then select "Switch to: .NET Core PowerShell Global Tool" and it fails again (with the same red error message and the same error logs as described in the other issue #2119).

Here's my workaround for PS7 to work:
Adding the following to the settings.json, in my case C:\Users\Pascal Ried\AppData\Roaming\Code\User\settings.json to
"terminal.integrated.shell.windows": "P:\\IDE\\PowerShell\\7\\pwsh.exe", "powershell.powerShellDefaultVersion": "Windows PowerShell (x64)", "powershell.powerShellAdditionalExePaths": [ { "versionName": "PowerShell 7", "exePath": "P:\\IDE\\PowerShell\\7\\pwsh.exe" } ],
and then selecting "Switch to: PowerShell 7" in the Session Menu.

Maybe this helps someone (or future me) with the same problem.
Basically I think there is a problem with the "Global Tool" but don't know much more.

Needs-Repro-Info Resolution-External

Most helpful comment

Okay, it works now after running
````
dotnet tool uninstall powershell --global
dotnet tool install powershell --global

PS C:\Users\Pascal Ried> & "C:\Users\Pascal Ried.dotnet\tools\pwsh.exe" -c '$PSVersionTable'

Name Value
---- -----
PSVersion 7.0.0
PSEdition Core
GitCommitId 7.0.0
OS Microsoft Windows 10.0.18362
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0鈥
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
````

Note: I did not update dotnet or anything else, yet.

Why? No idea but I guess it was a weird bug that's resolved by a complete reinstall of the dotnet global tool.
Thanks for the help.

All 13 comments

@Countryen thanks for the detailed explanation, how did you download "P:\\IDE\\PowerShell\\7\\pwsh.exe" this is helpful in us determining if the issue is being caused by the Global tool or happening for all versions of PS7...thanks!

@SydneyhSmith The issue was before using "P:\\IDE\\PowerShell\\7\\pwsh.exe" but I've downloaded it from here:

https://github.com/PowerShell/PowerShell/releases/tag/v7.0.0
PowerShell-7.0.0-win-x64.msi

I don't know how I've got the "Global Tool".

@rjmholt No but thanks for the link. I didn't know there are "dotnet global tools" before this issue.

Just FYI: The red error translates to something like:

Execution not possible because file or command not found.
Possible reasons:

  • You have misspelled an integrated dotnet-command.
  • You wanted to execute a .net core program but dotnet-C:\Users\Pascal doesn't exist.
  • You wanted to execute a global tool but in PATH is no executable file with the prefix dotnet.

Note that C:\Users\Pascal Ried\ is my actual user profile folder, although I am quite sure it was just C:\Users\pascal\ not long ago (did Windows change that?)

Maybe the space in my username causes problems because it doesn't show up in the error message fully?

So it looks like:

The PowerShell extension does its best to pick PowerShell up from well known installation paths, but won't find custom installations, so installing through the MSI to a custom path will mean you need to configure the extension to pick up your custom install as you've done.

The initial load failure seems to be a combination of picking up the .NET global tool first by default (which the extension will do when it doesn't find a PowerShell 7 installation elsewhere and no default version is set) and the dotnet global tool startup failing for some reason.

If you're able to share your extension logs, we might be able to work out what the invocation is that's failing when the extension tries to start the global tool.

Here's the log for the successful use of my "custom installation":
14.4.2020 23:40:05 [NORMAL] - PowerShell executable: P:\IDE\PowerShell\7\pwsh.exe 14.4.2020 23:40:05 [NORMAL] - PowerShell Editor Services args: Import-Module 'c:\Users\Pascal Ried\.vscode\extensions\ms-vscode.powershell-2020.3.0\modules\PowerShellEditorServices\PowerShellEditorServices.psd1'; Start-EditorServices -HostName 'Visual Studio Code Host' -HostProfileId 'Microsoft.VSCode' -HostVersion '2020.3.0' -AdditionalModules @('PowerShellEditorServices.VSCode') -BundledModulesPath 'c:\Users\Pascal Ried\.vscode\extensions\ms-vscode.powershell-2020.3.0\modules' -EnableConsoleRepl -LogLevel 'Diagnostic' -LogPath 'c:\Users\Pascal Ried\.vscode\extensions\ms-vscode.powershell-2020.3.0\logs\1586900405-d23742bc-a522-4cca-8b6a-470b8eefc5381586900384672\EditorServices.log' -SessionDetailsPath 'c:\Users\Pascal Ried\.vscode\extensions\ms-vscode.powershell-2020.3.0\sessions\PSES-VSCode-3616-280673' -FeatureFlags @() 14.4.2020 23:40:05 [NORMAL] - Waiting for session file 14.4.2020 23:40:05 [NORMAL] - Language server starting -- 14.4.2020 23:40:05 [NORMAL] - pwsh.exe started. 14.4.2020 23:40:05 [NORMAL] - PowerShell args: -NoProfile -NonInteractive -ExecutionPolicy Bypass -Command Import-Module 'c:\Users\Pascal Ried\.vscode\extensions\ms-vscode.powershell-2020.3.0\modules\PowerShellEditorServices\PowerShellEditorServices.psd1'; Start-EditorServices -HostName 'Visual Studio Code Host' -HostProfileId 'Microsoft.VSCode' -HostVersion '2020.3.0' -AdditionalModules @('PowerShellEditorServices.VSCode') -BundledModulesPath 'c:\Users\Pascal Ried\.vscode\extensions\ms-vscode.powershell-2020.3.0\modules' -EnableConsoleRepl -LogLevel 'Diagnostic' -LogPath 'c:\Users\Pascal Ried\.vscode\extensions\ms-vscode.powershell-2020.3.0\logs\1586900405-d23742bc-a522-4cca-8b6a-470b8eefc5381586900384672\EditorServices.log' -SessionDetailsPath 'c:\Users\Pascal Ried\.vscode\extensions\ms-vscode.powershell-2020.3.0\sessions\PSES-VSCode-3616-280673' -FeatureFlags @() 14.4.2020 23:40:07 [NORMAL] - Session file found 14.4.2020 23:40:07 [NORMAL] - Registering terminal PID log callback 14.4.2020 23:40:07 [NORMAL] - Registering terminal close callback 14.4.2020 23:40:07 [NORMAL] - pwsh.exe PID: 17788 14.4.2020 23:40:07 [NORMAL] - {"status":"started","languageServiceTransport":"NamedPipe","languageServicePipeName":"\\\\.\\pipe\\PSES_guydqevm.nri","debugServiceTransport":"NamedPipe","debugServicePipeName":"\\\\.\\pipe\\PSES_5ty1vrdf.fp1"} 14.4.2020 23:40:07 [NORMAL] - Language server started. 14.4.2020 23:40:07 [NORMAL] - Connecting to language service on pipe \\.\pipe\PSES_guydqevm.nri... 14.4.2020 23:40:07 [NORMAL] - Language service connected. 14.4.2020 23:40:24 [NORMAL] - Shutting down language client... 14.4.2020 23:40:24 [NORMAL] - Terminating PowerShell process...

And here is the one failing:
15.4.2020 00:00:04 [NORMAL] - Language server starting -- 15.4.2020 00:00:04 [NORMAL] - PowerShell executable: C:\Users\Pascal Ried\.dotnet\tools\pwsh.exe 15.4.2020 00:00:04 [NORMAL] - PowerShell args: -NoProfile -NonInteractive -ExecutionPolicy Bypass -Command Import-Module 'c:\Users\Pascal Ried\.vscode\extensions\ms-vscode.powershell-2020.3.0\modules\PowerShellEditorServices\PowerShellEditorServices.psd1'; Start-EditorServices -HostName 'Visual Studio Code Host' -HostProfileId 'Microsoft.VSCode' -HostVersion '2020.3.0' -AdditionalModules @('PowerShellEditorServices.VSCode') -BundledModulesPath 'c:\Users\Pascal Ried\.vscode\extensions\ms-vscode.powershell-2020.3.0\modules' -EnableConsoleRepl -LogLevel 'Diagnostic' -LogPath 'c:\Users\Pascal Ried\.vscode\extensions\ms-vscode.powershell-2020.3.0\logs\1586901604-d40a0912-8104-4e0b-bbe8-8feb792c69cd1586901373985\EditorServices.log' -SessionDetailsPath 'c:\Users\Pascal Ried\.vscode\extensions\ms-vscode.powershell-2020.3.0\sessions\PSES-VSCode-1512-409846' -FeatureFlags @() 15.4.2020 00:00:04 [NORMAL] - PowerShell Editor Services args: Import-Module 'c:\Users\Pascal Ried\.vscode\extensions\ms-vscode.powershell-2020.3.0\modules\PowerShellEditorServices\PowerShellEditorServices.psd1'; Start-EditorServices -HostName 'Visual Studio Code Host' -HostProfileId 'Microsoft.VSCode' -HostVersion '2020.3.0' -AdditionalModules @('PowerShellEditorServices.VSCode') -BundledModulesPath 'c:\Users\Pascal Ried\.vscode\extensions\ms-vscode.powershell-2020.3.0\modules' -EnableConsoleRepl -LogLevel 'Diagnostic' -LogPath 'c:\Users\Pascal Ried\.vscode\extensions\ms-vscode.powershell-2020.3.0\logs\1586901604-d40a0912-8104-4e0b-bbe8-8feb792c69cd1586901373985\EditorServices.log' -SessionDetailsPath 'c:\Users\Pascal Ried\.vscode\extensions\ms-vscode.powershell-2020.3.0\sessions\PSES-VSCode-1512-409846' -FeatureFlags @() 15.4.2020 00:00:04 [NORMAL] - pwsh.exe started. 15.4.2020 00:00:04 [NORMAL] - Waiting for session file 15.4.2020 00:02:04 [NORMAL] - Error occurred retrieving session file 15.4.2020 00:02:04 [NORMAL] - Language server startup failed. 15.4.2020 00:02:04 [ERROR] - The language service could not be started: 15.4.2020 00:02:04 [ERROR] - Timed out waiting for session file to appear.

See the attachment for the output from the "PowerShell Editor Services" when failing
ps-editor-services-log.txt

Hope that's correct, this is my settings file:
"powershell.developer.editorServicesLogLevel": "Diagnostic", "powershell editor services.trace.server":"verbose" }

Thanks for that!

Would you be able to run this from PowerShell and respond with the result:

& 'C:\Users\Pascal Ried\.dotnet\tools\pwsh.exe' -c '$PSVersionTable'

Same "red error" message:
image
(same in PowerShell and PowerShell 7)

Ok that's a good sign that there's an issue with the actual dotnet global tool here. Are you able to start the executable with & 'C:\Users\Pascal Ried\.dotnet\tools\pwsh.exe'? If so, what's the output of $PSVersionTable within that PowerShell?

No, can't start the pwsh.exe with that command, same error message.
I can, however, start the pwsh.exe with this line of commands:
cd 'C:\Users\Pascal Ried\.dotnet\tools\' & "pwsh.exe" -c '$PSVersionTable'

Output:
Name Value ---- ----- PSVersion 7.0.0 PSEdition Core GitCommitId 7.0.0 OS Microsoft Windows 10.0.18362 Platform Win32NT PSCompatibleVersions {1.0, 2.0, 3.0, 4.0鈥 PSRemotingProtocolVersion 2.3 SerializationVersion 1.1.0.1 WSManStackVersion 3.0

That's very odd. From my machine:

> & 'C:\Users\Robert Holt\.dotnet\tools\pwsh.exe' -c '$PSVersionTable'

Name                           Value
----                           -----
PSVersion                      7.0.0
PSEdition                      Core
GitCommitId                    7.0.0
OS                             Microsoft Windows 10.0.19041
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0鈥
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

I wonder if this is a bug in your particular dotnet version. It might be worth updating it to see if that changes anything.

Otherwise, if you don't want the global tool, I'd recommend uninstalling it, since you already have an MSI installation

Okay, it works now after running
````
dotnet tool uninstall powershell --global
dotnet tool install powershell --global

PS C:\Users\Pascal Ried> & "C:\Users\Pascal Ried.dotnet\tools\pwsh.exe" -c '$PSVersionTable'

Name Value
---- -----
PSVersion 7.0.0
PSEdition Core
GitCommitId 7.0.0
OS Microsoft Windows 10.0.18362
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0鈥
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
````

Note: I did not update dotnet or anything else, yet.

Why? No idea but I guess it was a weird bug that's resolved by a complete reinstall of the dotnet global tool.
Thanks for the help.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

inthemedium picture inthemedium  路  3Comments

guidooliveira picture guidooliveira  路  3Comments

daviwil picture daviwil  路  4Comments

pcgeek86 picture pcgeek86  路  4Comments

keposet picture keposet  路  3Comments