PSScriptAnalyzer: NullReferenceException on PSShouldProcess Rule.

Before submitting a bug report:

  • Make sure you are able to repro it on the latest released version
  • Perform a quick search for existing issues to check if this bug has already been reported

Steps to reproduce

I’m using PowerShellBuild and my module was made with Stucco.

I haven’t changed the template. And the Analyze task was working fine yesterday.

I can’t give steps to reproduce yet, working on it. Could I send someone my zipped module ? Not ready to make my code full public.


If an unexpected error was thrown then please report the full error details using e.g. $error[0] | Select-Object *

PSMessageDetails      : 
Exception             : System.NullReferenceException: Object reference not set to an instance of an object.
                           at Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.UseShouldProcessCorrectly.TryGetShouldProcessValueFromAst(FunctionInfo functionInfo, Boolean& hasShouldProcessSet)
                           at Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.UseShouldProcessCorrectly.SupportsShouldProcess(String cmdName)
                           at Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.UseShouldProcessCorrectly.CheckForSupportShouldProcess()
                           at Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.UseShouldProcessCorrectly.<AnalyzeScript>d__7.MoveNext()
                           at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
                           at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
                           at Microsoft.Windows.PowerShell.ScriptAnalyzer.ScriptAnalyzer.<>c__DisplayClass83_1.<AnalyzeSyntaxTree>b__2()
TargetObject          : C:\Users\avezina\gitrepos\etl.devops.serviceManagement\Output\ServiceManagement\0.6.2\Formatting\Deployment.format.ps1
CategoryInfo          : InvalidOperation: (C:\Users\avezin...ment.format.ps1:String) [Invoke-ScriptAnalyzer], NullReferenceException
FullyQualifiedErrorId : RULE_ERROR,Microsoft.Windows.PowerShell.ScriptAnalyzer.Commands.InvokeScriptAnalyzerCommand
ErrorDetails          : 
InvocationInfo        : System.Management.Automation.InvocationInfo
ScriptStackTrace      : at Test-PSBuildScriptAnalysis, C:\Users\avezina\Documents\WindowsPowerShell\Modules\PowerShellBuild\0.4.0\Public\Test-PSBuildScriptAnalysis.ps1: line 31
                        at <ScriptBlock>, C:\Users\avezina\Documents\WindowsPowerShell\Modules\PowerShellBuild\0.4.0\psakeFile.ps1: line 66
                        at Invoke-Task, C:\Users\avezina\Documents\WindowsPowerShell\Modules\psake\4.8.0\public\Invoke-Task.ps1: line 108
                        at <ScriptBlock>, C:\Users\avezina\Documents\WindowsPowerShell\Modules\psake\4.8.0\public\Invoke-psake.ps1: line 300
                        at ExecuteInBuildFileScope, C:\Users\avezina\Documents\WindowsPowerShell\Modules\psake\4.8.0\private\ExecuteInBuildFileScope.ps1: line 55
                        at Invoke-psake, C:\Users\avezina\Documents\WindowsPowerShell\Modules\psake\4.8.0\public\Invoke-psake.ps1: line 258
                        at <ScriptBlock>, C:\Users\avezina\gitrepos\etl.devops.serviceManagement\build.ps1: line 42
                        at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo : {}



Environment data

> $PSVersionTable

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


> (Get-Module -ListAvailable PSScriptAnalyzer).Version | ForEach-Object { $_.ToString() }
1.19.0

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 26 (10 by maintainers)

Most upvoted comments

I will need to install it.

Gonna spin a vm to try.

Final edit I had my module still installed. (That damn PS5 bug with the classes) Removed it, made sure it wasn’t installed anymore. Closed VSCode. Reopened VSCode. My Analyze task now works, no PSSA errors.

Thanks again for your help and patience.

Hmmm, in that case try rjmholt_msft@outlook.com

After looking at my version control,

  • June 29th
    • My Machine : Doesn’t work today (pretty sure it worked back then)
    • AzureDevOps Pipeline (windows-latest) : Works
  • July 5th
    • My Machine : Doesn’t work
    • AzureDevOps Pipeline (windows-latest) : Worked

EDIT : I wasn’t analyzing checked-in code. ignore this comment.