Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot execute PowerShell scripts with PowerShell Extension v2022.11.0 after the latest upgrade #4278

Closed
6 tasks done
joshuahipple opened this issue Nov 21, 2022 · 11 comments
Closed
6 tasks done
Assignees
Labels
Area-Engine Issue-Bug A bug to squash. Resolution-Fixed Will close automatically.

Comments

@joshuahipple
Copy link

Prerequisites

  • I have written a descriptive issue title.
  • I have searched all open and closed issues to ensure it has not already been reported.
  • I have read the troubleshooting guide.
  • I am sure this issue is with the extension itself and does not reproduce in a standalone PowerShell instance.
  • I have verified that I am using the latest version of Visual Studio Code and the PowerShell extension.
  • If this is a security issue, I have read the security issue reporting guidance.

Summary

Issue:

Cannot execute PowerShell scripts with PowerShell Extension v2022.11.0 after the latest upgrade. Standalone commands run fine in the Terminal window but scripts open will not execute. After reading through the logs I discovered the following workaround which has fixed the issue.

Workaround- Install the psscriptanalyzer module:

install-module psscriptanalyzer -force -scope AllUsers

Error message:

The terminal process "C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe '-NoProfile', '-ExecutionPolicy', 'Bypass', '-Command', 'Import-Module 'c:\Users\xxxxxxx.vscode\extensions\ms-vscode.powershell-2022.11.0\modules\PowerShellEditorServices\PowerShellEditorServices.psd1'; Start-EditorServices -HostName 'Visual Studio Code Host' -HostProfileId 'Microsoft.VSCode' -HostVersion '2022.11.0' -AdditionalModules @('PowerShellEditorServices.VSCode') -BundledModulesPath 'c:\Users\xxxxxxx.vscode\extensions\ms-vscode.powershell-2022.11.0\modules' -EnableConsoleRepl -StartupBanner "PowerShell Extension v2022.11.0
Copyright (c) Microsoft Corporation.

https://aka.ms/vscode-powershell
Type 'help' to get help.
" -LogLevel 'Normal' -LogPath 'c:\Users\xxxxxxx\AppData\Roaming\Code\User\globalStorage\ms-vscode.powershell\logs\1669041740-cc28b74a-49e7-4f2c-9e4b-db582deda4051669041688081\EditorServices.log' -SessionDetailsPath 'c:\Users\xxxxxxx\AppData\Roaming\Code\User\globalStorage\ms-vscode.powershell\sessions\PSES-VSCode-1372-299504.json' -FeatureFlags @() '" terminated with exit code: 1.


vscode-powershell.log

11/21/2022 9:42:20 AM [NORMAL] - PowerShell Extension v2022.11.0
11/21/2022 9:42:20 AM [NORMAL] - powershell.exe started.
11/21/2022 9:42:22 AM [NORMAL] - Session file found!
11/21/2022 9:42:22 AM [NORMAL] - Session details: {"status":"started","languageServiceTransport":"NamedPipe","languageServicePipeName":"\\.\pipe\PSES_kmvut4z3.cbi","debugServiceTransport":"NamedPipe","debugServicePipeName":"\\.\pipe\PSES_blhdox0v.t1d"}
11/21/2022 9:42:47 AM [ERROR] - The PowerShell Extension Terminal has stopped, would you like to restart it? IntelliSense and other features will not work without it!
11/21/2022 9:53:18 AM [NORMAL] - Terminating PowerShell process...
11/21/2022 9:53:18 AM [NORMAL] - Waiting for session file...
11/21/2022 9:53:20 AM [NORMAL] - Session file found!
11/21/2022 9:53:20 AM [NORMAL] - Language service socket connected.


EditorServices.log

System.ArgumentNullException: Value cannot be null.
Parameter name: path1
at System.IO.Path.Combine(String path1, String path2)
at Microsoft.PowerShell.EditorServices.Services.WorkspaceService.ResolveRelativeScriptPath(String baseFilePath, String relativePath)
2022-11-21 09:42:27.243 -05:00 [INF] Unable to find PSSA settings file at 'PSScriptAnalyzerSettings.psd1'. Loading default rules.
2022-11-21 09:42:27.243 -05:00 [INF] PSScriptAnalyzer settings file not found. Falling back to default rules
2022-11-21 09:53:22.729 -05:00 [INF] ReadLine overridden with 'Microsoft.PowerShell.EditorServices.Services.PowerShell.Console.PsrlReadLine'
2022-11-21 09:53:24.502 -05:00 [WRN] No ConfigurationItems have been defined, configuration won't surface any configuration from the client!
2022-11-21 09:53:24.542 -05:00 [ERR] Could not resolve Script Analyzer settings path due to null or empty workspaceRootPath.
2022-11-21 09:53:25.371 -05:00 [ERR] Could not resolve relative script path
baseFilePath =
relativePath = PSScriptAnalyzerSettings.psd1

PowerShell Version

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

Visual Studio Code Version

1.73.1
6261075646f055b99068d3688932416f2346dd3b
x64

Extension Version

ms-vscode.powershell@2022.11.0

Steps to Reproduce

Currently this issue only appears on systems that had Code installed that then upgraded to the latest version of the PowerShell extension.

Visuals

No response

Logs

No response

@joshuahipple joshuahipple added the Issue-Bug A bug to squash. label Nov 21, 2022
@ghost ghost added the Needs: Triage Maintainer attention needed! label Nov 21, 2022
@andyleejordan
Copy link
Member

Did you have any workspace folders open, or were you testing sans-workspace? Installing PSScriptAnalyzer should have no effect as it is loaded from the bundled modules path folder, but your logs indicate a failure to resolve the workspace path.

Perhaps enable diagnostic logging and try to repro?

Thanks!

@andyleejordan andyleejordan added Needs: Repro Info 🤔 and removed Needs: Triage Maintainer attention needed! labels Nov 21, 2022
@joshuahipple
Copy link
Author

joshuahipple commented Nov 22, 2022

I noticed this behavior on 2 different systems however I have not been able to repro the issue thus far. I downloaded and installed 1.73.0 as well as PowerShell extension 2022.10.0 on two separate test machines. Also installing the same modules that I had loaded on my systems that reported the issue. No errors reported before or after updating to 2022.11.0.

If no one else has come across then likely something within our environment for further review. I think this can be closed out for now. If it returns, then next steps are I will enable diagnostic logging.

@andyleejordan
Copy link
Member

Sounds good, thanks!

@joshuahipple
Copy link
Author

Issue returned today and this was the error message. I enabled Diagnostic logging and after about 20 minutes the issue resolved itself after multiple attempts. Also attached EditorServices logs from working and failed sessions. Will investigate again if it returns next week.

EditorServices_good.log
EditorServices_bad.log

Exception encountered starting EditorServices. Exception logged in D:\a\_work\1\s\src\PowerShellEditorServices.Hosting\Commands\StartEditorServicesCommand.cs on line 238 in EndProcessing:
System.MissingMethodException: Method not found: '!0 OmniSharp.Extensions.JsonRpc.IJsonRpcHandlerRegistry`1.OnJsonRequest(System.String, System.Func`2<Newtonsoft.Json.Linq.JToken,System.Threading.Tasks.Task`1<Newtonsoft.Json.Linq.JToken>>, OmniSharp.Extensions.JsonRpc.JsonRpcHandlerOptions)'.
   at Microsoft.PowerShell.EditorServices.Server.PsesDebugServer.<StartAsync>d__12.MoveNext()
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start[TStateMachine](TStateMachine& stateMachine)
   at Microsoft.PowerShell.EditorServices.Server.PsesDebugServer.StartAsync()
   at Microsoft.PowerShell.EditorServices.Hosting.EditorServicesRunner.<StartDebugServer>d__11.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.PowerShell.EditorServices.Hosting.EditorServicesRunner.<CreateEditorServicesAndRunUntilShutdown>d__9.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.PowerShell.EditorServices.Commands.StartEditorServicesCommand.EndProcessing()

@andyleejordan
Copy link
Member

Can you explain the timeline of events for me? I'm most curious about how you're activating the extension. Is it unactivated, and then you're activating it by starting a debug configuration to debug a script?

@TheMasterPrawn
Copy link

Same problem

$PSVersionTable
PSVersion 5.1.22000.832
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.22000.832
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
pslog.txt

I am working in this version of powershell and as of yesterday I am constantly seeing the issue above and am completely perplexed as to how this is happening.

@andyleejordan
Copy link
Member

I think this is another issue caused by PowerShell/PowerShellEditorServices#1947, oof.

@andyleejordan
Copy link
Member

@joshuahipple can you please try the latest PowerShell Preview for VS Code and see if this is fixed?

@andyleejordan andyleejordan added the Needs: Fix Verification Please verify the fix for us! label Nov 29, 2022
@joshuahipple
Copy link
Author

@andschwa - Thanks for the update. I did discover the steps to reproduce the issue.

Repro steps:

  1. Install AzureADPreview module
  2. Open fresh instance of VS Code (in my case 1.73.1)
  3. Open PowerShell script that has command "Connect-AzureAD" and run in PS 5.1. See attached AzureAD_test_1.ps1
  4. "EditorServices" error will be shown

Interesting to note that the error did not manifest if running a separate script (example: CIM_test_2.ps1) first then run the AzureAD script from step 3.

Good news!! I tested the PowerShell Preview for VS Code and then it resolved the issue and could not be repro. Thanks again for working to help resolve this issue.

P.S. I am aware that AzureADPreview is being deprecated by Microsoft but there are still several identity cmdlets that have not made it to the Microsoft.Graph module and are needed such as Get-MgPrivilegedAccessResourceRoleAssignment .

AzureAD_test_1.ps1.txt
CIM_test_2.ps1.txt

@andyleejordan
Copy link
Member

Thanks for those repro steps! They confirm my suspicion that it was caused by the GAC returning an older version of Newtonsoft.Json (which was being loaded from the AzureAD module's directory) and that this mismatched version was the cause of the problem.

@andyleejordan andyleejordan added Resolution-Fixed Will close automatically. and removed Needs: Fix Verification Please verify the fix for us! labels Nov 30, 2022
@ghost ghost closed this as completed Nov 30, 2022
@ghost
Copy link

ghost commented Nov 30, 2022

This issue has been marked as fixed. It has been automatically closed for housekeeping purposes.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Engine Issue-Bug A bug to squash. Resolution-Fixed Will close automatically.
Projects
None yet
Development

No branches or pull requests

3 participants