PowerShell / vscode-powershell

Provides PowerShell language and debugging support for Visual Studio Code
https://marketplace.visualstudio.com/items/ms-vscode.PowerShell
MIT License
1.72k stars 492 forks source link

Can not run PowerShell code selection (f8) in Visual Studio #5097

Open firthro opened 3 days ago

firthro commented 3 days ago

Prerequisites

Summary

I am experiencing a problem running PowerShell code interactively through Visual Studio Code. write-host "hello world" f8/ Run Selection will launch a PowerShell Extension that never completes.

I can run in the terminal and via PowerShell directlly.

If you terminate the PowerShell Services Client, the long error below appears (put intto the logs)

PowerShell Version

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

Visual Studio Code Version

1.95.3
x64

Extension Version

ms-vscode.powershell@2024.4.0

Steps to Reproduce

Save HelloWolrld.ps1 file with write-host "hello"

Select the line and press f8 in Visual Studio

Visuals

Screenshot 2024-11-19 115659

Logs

System.Management.Automation.CmdletProviderInvocationException: Access is denied ---> System.UnauthorizedAccessException: Access is denied ---> System.ComponentModel.Win32Exception: Access is denied --- End of inner exception stack trace --- at System.Management.Automation.Utils.NativeFileExists(String path) at Microsoft.PowerShell.Commands.FileSystemProvider.GetFileSystemInfo(String path, Boolean& isContainer) at Microsoft.PowerShell.Commands.FileSystemProvider.NormalizeThePath(String basepath, Stack1 tokenizedPathStack) at Microsoft.PowerShell.Commands.FileSystemProvider.NormalizeRelativePathHelper(String path, String basePath) at Microsoft.PowerShell.Commands.FileSystemProvider.NormalizeRelativePath(String path, String basePath) at System.Management.Automation.SessionStateInternal.NormalizeRelativePath(ProviderInfo provider, String path, String basePath, CmdletProviderContext context) --- End of inner exception stack trace --- at System.Management.Automation.Runspaces.PipelineBase.Invoke(IEnumerable input) at System.Management.Automation.PowerShell.Worker.ConstructPipelineAndDoWork(Runspace rs, Boolean performSyncInvoke) at System.Management.Automation.PowerShell.Worker.CreateRunspaceIfNeededAndDoWork(Runspace rsToUse, Boolean isSync) at System.Management.Automation.PowerShell.CoreInvokeHelper[TInput,TOutput](PSDataCollection1 input, PSDataCollection1 output, PSInvocationSettings settings) at System.Management.Automation.PowerShell.CoreInvoke[TInput,TOutput](PSDataCollection1 input, PSDataCollection1 output, PSInvocationSettings settings) at System.Management.Automation.PowerShell.Invoke[T](IEnumerable input, PSInvocationSettings settings) at Microsoft.PowerShell.EditorServices.Services.PowerShell.Utility.PowerShellExtensions.InvokeAndClear[TResult](PowerShell pwsh, PSInvocationSettings invocationSettings) at Microsoft.PowerShell.EditorServices.Services.PowerShell.Execution.SynchronousPowerShellTask1.ExecuteNormally(CancellationToken cancellationToken) | [Error - 11:22:47 AM] OmniSharp.Extensions.JsonRpc.DefaultRequestInvoker: Failed to handle request initialize 0 - System.Management.Automation.CmdletProviderInvocationException: Access is denied ---> System.UnauthorizedAccessException: Access is denied ---> System.ComponentModel.Win32Exception: Access is denied --- End of inner exception stack trace --- at System.Management.Automation.Utils.NativeFileExists(String path) at Microsoft.PowerShell.Commands.FileSystemProvider.GetFileSystemInfo(String path, Boolean& isContainer) at Microsoft.PowerShell.Commands.FileSystemProvider.NormalizeThePath(String basepath, Stack1 tokenizedPathStack) at Microsoft.PowerShell.Commands.FileSystemProvider.NormalizeRelativePathHelper(String path, String basePath) at Microsoft.PowerShell.Commands.FileSystemProvider.NormalizeRelativePath(String path, String basePath) at System.Management.Automation.SessionStateInternal.NormalizeRelativePath(ProviderInfo provider, String path, String basePath, CmdletProviderContext context) --- End of inner exception stack trace --- at System.Management.Automation.Runspaces.PipelineBase.Invoke(IEnumerable input) at System.Management.Automation.PowerShell.Worker.ConstructPipelineAndDoWork(Runspace rs, Boolean performSyncInvoke) at System.Management.Automation.PowerShell.Worker.CreateRunspaceIfNeededAndDoWork(Runspace rsToUse, Boolean isSync) at System.Management.Automation.PowerShell.CoreInvokeHelper[TInput,TOutput](PSDataCollection1 input, PSDataCollection1 output, PSInvocationSettings settings) at System.Management.Automation.PowerShell.CoreInvoke[TInput,TOutput](PSDataCollection1 input, PSDataCollection1 output, PSInvocationSettings settings) at System.Management.Automation.PowerShell.Invoke[T](IEnumerable input, PSInvocationSettings settings) at Microsoft.PowerShell.EditorServices.Services.PowerShell.Utility.PowerShellExtensions.InvokeAndClear[TResult](PowerShell pwsh, PSInvocationSettings invocationSettings) at Microsoft.PowerShell.EditorServices.Services.PowerShell.Execution.SynchronousPowerShellTask1.ExecuteNormally(CancellationToken cancellationToken) at Microsoft.PowerShell.EditorServices.Services.PowerShell.Execution.SynchronousPowerShellTask1.Run(CancellationToken cancellationToken) at Microsoft.PowerShell.EditorServices.Services.PowerShell.Execution.SynchronousTask1.ExecuteSynchronously(CancellationToken executorCancellationToken) --- 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.Services.PowerShell.Host.PsesInternalHost.d87.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 OmniSharp.Extensions.LanguageServer.Server.LanguageServer.<MediatR-IRequestHandler<OmniSharp-Extensions-LanguageServer-Protocol-Models-InternalInitializeParams\,OmniSharp-Extensions-LanguageServer-Protocol-Models-InitializeResult>-Handle>d81.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 OmniSharp.Extensions.LanguageServer.Server.Pipelines.SemanticTokensDeltaPipeline2.<Handle>d__0.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 OmniSharp.Extensions.LanguageServer.Server.Pipelines.ResolveCommandPipeline2.d3.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 MediatR.Pipeline.RequestPreProcessorBehavior`2.d2.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 MediatR.Pipeline.RequestPostProcessorBehavior2.<Handle>d__2.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 MediatR.Pipeline.RequestExceptionProcessorBehavior2.d2.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at MediatR.Pipeline.RequestExceptionProcessorBehavior`2.d2.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 MediatR.Pipeline.RequestExceptionActionProcessorBehavior2.<Handle>d__2.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at MediatR.Pipeline.RequestExceptionActionProcessorBehavior2.d2.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 OmniSharp.Extensions.JsonRpc.RequestRouterBase`1.<gInnerRoute|7_0>d.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 OmniSharp.Extensions.JsonRpc.RequestRouterBase`1.d7.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 OmniSharp.Extensions.JsonRpc.DefaultRequestInvoker.<>cDisplayClass10_0.<b__5>d.MoveNext() | Method='initialize' RequestId='0' [Warn - 11:22:47 AM] OmniSharp.Extensions.LanguageServer.Server.LspServerOutputFilter: Tried to send request or notification before initialization was completed and will be sent later OmniSharp.Extensions.JsonRpc.Server.Messages.InternalError | @Request='OmniSharp.Extensions.JsonRpc.Server.Messages.InternalError' [Error - 12:00:20 PM] Server initialization failed. Message: Pending response rejected since connection got disposed Code: -32097 [Error - 12:00:20 PM] Connection to PowerShell Editor Services (the Extension Terminal) was closed. See below prompt to restart! [Error - 12:00:20 PM] PowerShell Editor Services Client client: couldn't create connection to server. Message: Pending response rejected since connection got disposed Code: -32097

JustinGrote commented 3 days ago

Thanks for your submission! The error suggests your filesystem is unavailable (access denied).

I cannot reproduce, works fine for me. image

firthro commented 3 days ago

Hello

The root issue was a local security lockdown by the organisation. And this is now released it is working once more.

Thanks

From: Justin Grote @.> Sent: 19 November 2024 15:53 To: PowerShell/vscode-powershell @.> Cc: Firth, Robert @.>; Author @.> Subject: Re: [PowerShell/vscode-powershell] Can not run PowerShell code selection (f8) in Visual Studio (Issue #5097)

External Mail


Thanks for your submission! The error suggests your filesystem is unavailable (access denied).

I cannot reproduce, works fine for me. image.png (view on web)https://github.com/user-attachments/assets/481cfd73-d94a-4979-a4cf-935581f4b841

— Reply to this email directly, view it on GitHubhttps://github.com/PowerShell/vscode-powershell/issues/5097#issuecomment-2486095734, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AGAUZQZPKA5R337UTDG54VD2BNNGBAVCNFSM6AAAAABSB4BAACVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDIOBWGA4TKNZTGQ. You are receiving this because you authored the thread.Message ID: @.**@.>> Please see our Privacy Policy to learn how we handle personal data – www.schroders.com/en/privacy-policy

Visit Schroders Talking Point for market news and expert views http://www.schroders.com/talkingpoint

This email is confidential and is for the addressee only. If it has been sent to you in error, please do not forward it or copy it or act on its contents, but report it to @.*** For important disclaimers and regulatory information, please refer to www.schroders.com (Privacy Statement; and Important Information).

Schroder Investment Management Limited is authorised and regulated by the Financial Conduct Authority (FCA reference number 119348). Registered in England and Wales under company number 1893220 with registered office address at 1 London Wall Place, London EC2Y 5AU. VAT identification number GB 243 8687 30.

github-actions[bot] commented 3 days ago

This issue has been labeled as resolved, please verify the provided fix (or other reason).