Vscode-powershell: PowerShell extension crashes when dealing with UNC paths

Created on 1 Apr 2019  路  20Comments  路  Source: PowerShell/vscode-powershell

System Details


System Details Output


Issue Description

I am experiencing a problem with...

Expected Behaviour

-- Description of what should be happening --

Actual Behaviour

-- Description of what actually happens --

Attached Logs

Follow the instructions in the troubleshooting docs
about capturing and sending logs.

Area-Pester Issue-Bug Needs-Repro-Info

Most helpful comment

I'm seeing the same behaviour as @ili101. Local files are fine, but scripts located at UNC paths exhibit crashing.

All 20 comments

Please attach logs - see the troubleshooting docs. Without version info (extension, vscode, os), logs and/or repro instructions, this issue isn't very actionable.

Just doing that now, I thought I had attached them

Issue Description:

CodeLens is causing interactive powershell console to crash
This is similar to the issue #887
I'm wondering if a solution for this issue has been found.

I'm seeing the same behavior both with code in the repo (github and Enterprise), it seems to have just started a week ago or so, after adding the latest upgrade. The video shown here is the same thing i'm seeing.

System Details:

[system.environment]::OsVersion.Version *
Major Minor Build Revision
6 3 9600 0

PS> code -v
1.32.3
a3db5be9b5c6ba46bb7555ec5d60178ecc2eaae4
x64

PS> $PsVersionTable
Name Value
PSVersion 5.1.14409.1018
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.14409.1018
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

PS> $pseditor.EditorServicesVersion
Major Minor Build Revision
1 12 0 0

### Expected Behavior
Codlens places a reference comment above a function

Actual Behavior
for this example: After entering a function scriptblock, the codelens seems to want to a reference above the scriptblock, moves the block down, looks like its trying, but then fails the block moves backup and the interactive console crashes.

Logfiles:

EditorServices.log

vscode-powershell.log

2019-03-31_10-22-05

vscode-powershell.log
EditorServices.log
Same Problem but the error in my logs is different, It happens to me when the file with the function is on a network share (\serverpathfile.ps1) if the file is local it's not crashing for me. as @BruceAWilliams shows with CodeLens disabled it's not crashing.

I'm seeing the same behaviour as @ili101. Local files are fine, but scripts located at UNC paths exhibit crashing.

The relevant log entry seems to be this one:

2019-04-01 12:36:03.813 [ERROR] tid:5 in 'OnListenTaskCompleted' C:\PowerShellEditorServices\src\PowerShellEditorServices.Protocol\MessageProtocol\ProtocolEndpoint.cs: line 391
    ProtocolEndpoint message loop terminated due to unhandled exception:

    System.AggregateException: One or more errors occurred. ---> System.NotSupportedException: The given path's format is not supported.
       at System.Security.Permissions.FileIOPermission.EmulateFileIOPermissionChecks(String fullPath)
       at System.Security.Permissions.FileIOPermission.QuickDemand(FileIOPermissionAccess access, String fullPath, Boolean checkForDuplicates, Boolean needFullPath)
       at Microsoft.PowerShell.EditorServices.Workspace.ResolveFilePath(String filePath)
       at Microsoft.PowerShell.EditorServices.Workspace.GetFile(String filePath)
       at Microsoft.PowerShell.EditorServices.CodeLenses.CodeLensFeature.<HandleCodeLensResolveRequest>d__6.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.Protocol.MessageProtocol.MessageDispatcher.<DispatchMessage>d__7.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.Protocol.MessageProtocol.ProtocolEndpoint.<ListenForMessages>d__36.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.Utility.AsyncContext.Start(Func`1 asyncMainFunc, ILogger logger)
       at System.Threading.Tasks.Task.Execute()
       --- End of inner exception stack trace ---
    ---> (Inner Exception #0) System.NotSupportedException: The given path's format is not supported.
       at System.Security.Permissions.FileIOPermission.EmulateFileIOPermissionChecks(String fullPath)
       at System.Security.Permissions.FileIOPermission.QuickDemand(FileIOPermissionAccess access, String fullPath, Boolean checkForDuplicates, Boolean needFullPath)
       at Microsoft.PowerShell.EditorServices.Workspace.ResolveFilePath(String filePath)
       at Microsoft.PowerShell.EditorServices.Workspace.GetFile(String filePath)
       at Microsoft.PowerShell.EditorServices.CodeLenses.CodeLensFeature.<HandleCodeLensResolveRequest>d__6.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.Protocol.MessageProtocol.MessageDispatcher.<DispatchMessage>d__7.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.Protocol.MessageProtocol.ProtocolEndpoint.<ListenForMessages>d__36.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.Utility.AsyncContext.Start(Func`1 asyncMainFunc, ILogger logger)
       at System.Threading.Tasks.Task.Execute()<---

It seems to be occurring in this method: https://github.com/PowerShell/PowerShellEditorServices/blob/8c66fa912ecfac4e93345ca96dc49d1787f81f1d/src/PowerShellEditorServices/Workspace/Workspace.cs#L464-L487

Whatever .NET API we're using to resolve file paths as URIs seems to not like UNC paths, so we'll need to determine what the best way to handle those is.

I was experiencing the repeated PowerShell extension crash until I disabled Code Lens in settings. My logs also have the The given path's format is not supported. error as noted above. As others mentioned I have UNC paths in the script that load other functions via dot-sourcing. I also noticed that upon saving the file, the dot-sourced UNC path gets removed regardless if Code Lens is enabled or not. Example:

. \\server\gitmaster\functions\function.ps1

gets changed to this on save:

. function.ps1

I am working around it by using Set-Location to the path of the function before dot-sourcing the function which allows me to use . .\function.ps1 but I hope this gets addressed before I have to put that workaround into too many files.

Do you have this setting configured: "editor.formatOnSave": true? We believe there is an issue with code formatting that is removing parts of dot-sourced paths.

Do you have this setting configured: "editor.formatOnSave": true? We believe there is an issue with code formatting that is removing parts of dot-sourced paths.

Yes I do. I will disable it for the near-term. Thanks!

I'm having the same experience as the first posts where I have files on a network share. Loading local files works better without crashes, but there are still issues with "X references" for each function.

I'm having this issues without using any UNC paths inside my ps1 files. Didn't have these issues prior to 1.12.0.
powershell_vsc

Can you attach log files for the extension? See troubleshooting docs for instructions on how to do that.

@BruceAWilliams I think I've fixed the UNC path issues other folks are seeing but your log isn't detailed enought to see what is going on. Can you set your log level to diagnostic temporarily, repro the issue and attach the logs here? Thanks.

Put this in you user settings file to enable diagnostic level logging:

    "powershell.developer.editorServicesLogLevel": "Diagnostic",

I saw that my VSC loaded some UNC-path dirs, even though I don't open the files themselves.
EditorServices.log
metadata.txt
vscode-powershell.log

I saw that my VSC loaded some UNC-path dirs, even though I don't open the files themselves.

It's trying to resolve references in the script; it starts from what you've got open and works backwards.

Hi all, can you try one of these builds:

PowerShell and PowerShell Preview release candidates.zip

This should have the UNC path fix. Note, if you've never used the Preview extension, look at these steps.

If you've never installed a VSIX before, here are the steps.

I installed the the v1.12.1 extension, reloaded vscode and when I executed Import-module \\saas\saasops\Users\Al\Github\certificate-tracking\CertificateTracking.psd1 in the vscode terminal window, it threw the error below. Executing the import-module a second time ran without error. Not sure if this is specific to my set up but thought I'd share it.

Exception             : System.Management.Automation.MethodInvocationException: Exception calling "InvokeScript" with "4" argument(s): "Index was outside the bounds of the array." ---> 
                        System.Management.Automation.CmdletInvocationException: Index was outside the bounds of the array. ---> System.IndexOutOfRangeException: Index was outside the 
                        bounds of the array.
                           at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
                           at Sqlcollaborative.Dbatools.Commands.SetDbatoolsConfigCommand.ExecuteInitialize() in 
                        F:\Code\Github\dbatools\bin\projects\dbatools\dbatools\Commands\SetDbatoolsConfigCommand.cs:line 308
                           at Sqlcollaborative.Dbatools.Commands.SetDbatoolsConfigCommand.ProcessRecord() in 
                        F:\Code\Github\dbatools\bin\projects\dbatools\dbatools\Commands\SetDbatoolsConfigCommand.cs:line 275
                           at System.Management.Automation.CommandProcessor.ProcessRecord()
                           --- End of inner exception stack trace ---
                           at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception)
                           at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
                           at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
                           at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
                           at System.Management.Automation.Interpreter.Interpreter.Run(InterpretedFrame frame)
                           at System.Management.Automation.Interpreter.LightLambda.RunVoid1[T0](T0 arg0)
                           at System.Management.Automation.ScriptBlock.InvokeWithPipeImpl(ScriptBlockClauseToInvoke clauseToInvoke, Boolean createLocalScope, Dictionary`2 
                        functionsToDefine, List`1 variablesToDefine, ErrorHandlingBehavior errorHandlingBehavior, Object dollarUnder, Object input, Object scriptThis, Pipe outputPipe, 
                        InvocationInfo invocationInfo, Object[] args)
                           at System.Management.Automation.ScriptBlock.<>c__DisplayClass57_0.<InvokeWithPipe>b__0()
                           at System.Management.Automation.Runspaces.RunspaceBase.RunActionIfNoRunningPipelinesWithThreadCheck(Action action)
                           at System.Management.Automation.ScriptBlock.InvokeWithPipe(Boolean useLocalScope, ErrorHandlingBehavior errorHandlingBehavior, Object dollarUnder, Object input, 
                        Object scriptThis, Pipe outputPipe, InvocationInfo invocationInfo, Boolean propagateAllExceptionsToTop, List`1 variablesToDefine, Dictionary`2 functionsToDefine, 
                        Object[] args)
                           at System.Management.Automation.ScriptBlock.DoInvokeReturnAsIs(Boolean useLocalScope, ErrorHandlingBehavior errorHandlingBehavior, Object dollarUnder, Object 
                        input, Object scriptThis, Object[] args)
                           at System.Management.Automation.CommandInvocationIntrinsics.InvokeScript(ScriptBlock sb, Boolean useNewScope, PipelineResultTypes writeToPipeline, IList input, 
                        Object[] args)
                           at System.Management.Automation.CommandInvocationIntrinsics.InvokeScript(Boolean useLocalScope, ScriptBlock scriptBlock, IList input, Object[] args)
                           at CallSite.Target(Closure , CallSite , Object , Boolean , Object , Object , Object )
                           --- End of inner exception stack trace ---
                           at System.Management.Automation.ExceptionHandlingOps.ConvertToMethodInvocationException(Exception exception, Type typeToThrow, String methodName, Int32 numArgs, 
                        MemberInfo memberInfo)
                           at CallSite.Target(Closure , CallSite , Object , Boolean , Object , Object , Object )
                           at Import-ModuleFile(Closure , FunctionContext )
TargetObject          : 
CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
FullyQualifiedErrorId : CmdletInvocationException
ErrorDetails          : 
InvocationInfo        : System.Management.Automation.InvocationInfo
ScriptStackTrace      : at Import-ModuleFile, C:\Users\dal\Documents\WindowsPowerShell\Modules\dbatools\0.9.715\dbatools.psm1: line 40
                        at <ScriptBlock>, C:\Users\dal\Documents\WindowsPowerShell\Modules\dbatools\0.9.715\dbatools.psm1: line 224
                        at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo : {}
PSMessageDetails      : 

@adegutis Looks like that's happening within dbatools. You might wanna point that over to them if it happens regularly.

@BruceAWilliams Can you try a special drop of the extension to see if it fixes the original issue you brought up? The instructions are in third message up from this one. Thanks!

Closing as this fix has been merged and will be available in the next release

Was this page helpful?
0 / 5 - 0 ratings