question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Session menu fails to open when PowerShell extension is starting

See original GitHub issue

System Details

System Details Output
### VSCode version: 1.48.1 3dd905126b34dcd4de81fa624eb3a8cbe7485f13 x64

### VSCode extensions:
bierner.markdown-mermaid@1.8.1
DavidAnson.vscode-markdownlint@0.36.3      
EditorConfig.EditorConfig@0.15.1
emmanuelbeziat.vscode-great-icons@2.1.47   
ms-vscode.powershell@2020.6.0
streetsidesoftware.code-spell-checker@1.9.0
yzhang.markdown-all-in-one@3.2.0


### PSES version:

### PowerShell version:

Name                           Value
----                           -----
PSVersion                      5.1.18362.752
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.18362.752
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Issue Description

I am experiencing a problem with the PowerShell session menu during extension loading.

Expected Behaviour

Clicking on the button 🔄 Starting PowerShell (at the bottom-right) should do nothing (if the extension is not ready) or should open the PowerShell session menu.

Actual Behaviour

The PowerShell session menu fails to open and the following error notification is displayed:

Running the contributed command: ‘PowerShell.ShowSessionMenu’ failed.

Note: with PowerShellGet and PackageManagement up-to-date, if I wait for the extension to fully load, 🔄 Starting PowerShell button is replaced by the PowerShell version (e.g. [>] 5.1) and the session menu can now be opened.

Attached Logs (and some further investigation)

The following error message is logged (Extension Host):

[2020-08-22 14:53:14.183] [exthost] [error] TypeError: Cannot read property 'displayVersion' of undefined
	at SessionManager.showSessionMenu (c:\Users\xxxx\.vscode\extensions\ms-vscode.powershell-2020.6.0\out\src\session.js:520:55)
	at c:\Users\xxxx\.vscode\extensions\ms-vscode.powershell-2020.6.0\out\src\session.js:303:91
	at _executeContributedCommand (c:\Users\xxxx\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:642:374)
	[...]

When I debug some values in session.js (showSessionMenu method), I get this:

  • availablePowerShellExes (L504): [{"exePath":"C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe","displayName":"Windows PowerShell (x64)","knownToExist":true},{"exePath":"C:\\Windows\\SysWOW64\\WindowsPowerShell\\v1.0\\powershell.exe","displayName":"Windows PowerShell (x86)","knownToExist":true}]
  • this.PowerShellExeDetails (L514): {"exePath":"C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe","displayName":"Windows PowerShell (x64)","knownToExist":true}
  • currentPowerShellExe (L514): undefined
  • this.versionDetails (L514): undefined

this.versionDetails.displayVersion (L516) logically fails and throws the previous TypeError.

The following modification (L512) seems to fix the issue (and makes sense to me):

  const currentPowerShellExe = availablePowerShellExes
-                     .find((item) => item.displayName.toLowerCase() === this.PowerShellExeDetails.displayName);
+                     .find((item) => item.displayName.toLowerCase() === this.PowerShellExeDetails.displayName.toLowerCase());

With this modification, the first value of availablePowerShellExes is now assigned to currentPowerShellExe and the following ternary condition assigns currentPowerShellExe.displayName to powerShellSessionName without throwing the previous error.

This proposal may not be the right one. You may even consider that this issue is not really valid as the session menu succeeds to open when the extension is fully started. Maybe that a click on the button should not call the ShowSessionMenu command while the extension is loading?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
jeffpatton1971commented, Sep 24, 2020
1reaction
SydneyhSmithcommented, Sep 8, 2020

Thanks @GaelGirodon unfortunately we do not know when we will have the capacity to fix this so I will mark it as up for grabs…if you do decide to contribute we can help with the process–thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Visual Studio Code Powershell startup failure - Stack Overflow
Cannot debug or run a Powershell script until the PowerShell session has started. Wait for PowerShell session to finish starting and try again....
Read more >
Getting Started with PowerShell - Microsoft Learn
The solution to this problem is to run PowerShell as a domain user who is a local administrator. This is how my second...
Read more >
Fix for PowerShell Script cannot be loaded because running ...
On trying to run a PowerShell script from the PowerShell console, received this error message: “File C:\temp\GenerateRpt.ps1 cannot be loaded ...
Read more >
Executing PowerShell Scripts FAQ and Tips & Tricks - HowTo ...
Right click on the Start Menu to quickly open PowerShell. How can I easily execute a PowerShell script? PowerShell Script button The easiest...
Read more >
Integrated Terminal in Visual Studio Code
It provides integration with the editor to support features like links and error detection. To open the terminal: Use the Ctrl+` keyboard shortcut...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found