question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NullReferenceException on PSShouldProcess Rule.

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:26 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
avezinaATastuscommented, Jul 8, 2020

I will need to install it.

Gonna spin a vm to try.

1reaction
avezinaATastuscommented, Jul 8, 2020

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

AvoidReservedCharInCmdlet throws System. ...
NullReferenceException sometimes due to CommandInfo. ... I found that it is specifically the PSShouldProcess rule that makes it not work.
Read more >
c# - What is a NullReferenceException, and how do I fix it?
This means the reference is null , and you cannot access members (such as methods) through a null reference. The simplest case: string...
Read more >
Object reference not set to an instance of an object | Page 2
A null reference means that it is trying to access something that doesn't exist. You either forgot to drag something in the editor,...
Read more >
NullReferenceException Class (System)
This exception occurs if you assume that each element of the array must contain a non-null value, and the value of the array...
Read more >
Object Reference Not Set to an Instance of an Object
This exception is thrown when you try to access a member—for instance, a method or a property—on a variable that currently holds a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found