PowerShell / PSScriptAnalyzer

Download ScriptAnalyzer from PowerShellGallery
https://www.powershellgallery.com/packages/PSScriptAnalyzer/
MIT License
1.87k stars 378 forks source link

System.InvalidOperationException from Invoke-ScriptAnalyzer command when debugging PSES #959

Open rkeithhill opened 6 years ago

rkeithhill commented 6 years ago

I've been debugging other issues in PSES and I'm seeing multiple instances of this exception. Can this be safely ignored or is there a problem here:

image

image

This was using Windows PowerShell 5.1 on Windows 10 FCU.

Copied over from PSES - https://github.com/PowerShell/PowerShellEditorServices/issues/572

bergmeister commented 6 years ago

@rkeithhill There is a possibility that it is related to #902, but #902 happens much more below the stack that you show, it has the same exception type but different message. Current research suggests that #902 seems to be due a thread safety bug in PowerShell itself (PSSA spawns a new thread for each rule btw). Can you give a more detailed stack trace and example scriptdefinition input to reproduce? Are you calling Invoke-ScriptAnalyzer -ScriptDefinition multiple times in the same PowerShell session or do you always start from a fresh session/runspace? Are you calling into PSSA multiple times with overlapping calls?

bergmeister commented 6 years ago

Bang. I had something similar today when attaching the debugger to it when debugging #966 . The exception gets swallowed as one can see but having an empty catch block seems to be rather a code smell... image