Skip to content

Powershell session terminates by "Format Document" on Windows 2008 R2 #2007

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

Closed
danielfeiler opened this issue Jun 4, 2019 · 7 comments · Fixed by PowerShell/PowerShellEditorServices#974
Labels
Issue-Bug A bug to squash.

Comments

@danielfeiler
Copy link

If I try to do teh action "Format Document on a Windows 2008 R2 machine I get the message "The PowerShell session has terminated due to an error, would you like to restart it?
Extension logfile is attached.
EditorServices.log

@rjmholt
Copy link
Contributor

rjmholt commented Jun 4, 2019

Relevant log info:

2019-06-04 09:20:39.575 [ERROR] tid:16 in 'Create' C:\PowerShellEditorServices\src\PowerShellEditorServices\Analysis\AnalysisService.cs: line 200
    Exception: PSScriptAnalyzer cannot be imported, AnalysisService will be disabled
    
    Microsoft.PowerShell.EditorServices.AnalysisServiceLoadException: PSScriptAnalyzer runspace pool could not be created ---> Microsoft.PowerShell.EditorServices.AnalysisServiceLoadException: Unable to find PSScriptAnalyzer module on the module path
       at Microsoft.PowerShell.EditorServices.AnalysisService.CreatePssaRunspacePool(PSModuleInfo& pssaModuleInfo)
       at Microsoft.PowerShell.EditorServices.AnalysisService.Create(String settingsPath, ILogger logger)
       --- End of inner exception stack trace ---
       at Microsoft.PowerShell.EditorServices.AnalysisService.Create(String settingsPath, ILogger logger)

2019-06-04 09:20:41.961 [NORMAL] tid:10 in 'Register' C:\PowerShellEditorServices\src\PowerShellEditorServices.VSCode\ComponentRegistration.cs: line 36
    PowerShell Editor Services VS Code module loaded.

2019-06-04 09:21:07.691 [ERROR] tid:46 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.NullReferenceException: Object reference not set to an instance of an object.
       at Microsoft.PowerShell.EditorServices.Protocol.Server.LanguageServer.<Format>d__66.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
       at Microsoft.PowerShell.EditorServices.Protocol.Server.LanguageServer.<HandleDocumentRangeFormattingRequest>d__62.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       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.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       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.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       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.NullReferenceException: Object reference not set to an instance of an object.
       at Microsoft.PowerShell.EditorServices.Protocol.Server.LanguageServer.<Format>d__66.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
       at Microsoft.PowerShell.EditorServices.Protocol.Server.LanguageServer.<HandleDocumentRangeFormattingRequest>d__62.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       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.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       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.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       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()<---
    

Looks like PSSA can't be loaded (which is strange since it's bundled with the extension) and then we don't handle the load failure properly

@rjmholt
Copy link
Contributor

rjmholt commented Jun 7, 2019

@danielfeiler Can you report the output of the following in the Integrated Console:

Import-Module PSScriptAnalyzer

@danielfeiler
Copy link
Author

danielfeiler commented Jun 7, 2019

@rjmholt of course:

PowerShell Integrated Console

PS C:\Users\danielfeiler> Import-Module PSScriptAnalyzer
Import-Module : The specified module 'PSScriptAnalyzer' was not loaded because no valid module file was found in any module 
directory.
At line:1 char:1
+ Import-Module PSScriptAnalyzer
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (PSScriptAnalyzer:String) [Import-Module], FileNotFoundException
    + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
 
PS C:\Users\danielfeiler> 

@rjmholt
Copy link
Contributor

rjmholt commented Jun 7, 2019

Hmmmm, that's very odd.

Have you altered $env:PSModulePath maybe?

Can you tell me what the following output:

  • gmo -list PSScriptAnalyzer
  • gci ~\.vscode\extensions\ms-vscode.powershell-2019.5.0\modules
  • $env:PSModulePath

@rjmholt
Copy link
Contributor

rjmholt commented Jun 7, 2019

Also you should be able to fix this immediately with Install-Module PSScriptAnalyzer -Scope CurrentUser

@SydneyhSmith
Copy link
Collaborator

@danielfeiler were you able to resolve this issue with @rjmholt 's suggestion above?

@SydneyhSmith
Copy link
Collaborator

Going to go ahead and close this as resolved but will re-open if you are still facing this issue--Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Bug A bug to squash.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants