You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If Invoke-Formatter with the PSAlignAssignmentStatementRule enabled is run against a hashtable that contains a key name specified as an object.property, a NullReferenceException error occurs.
Invoke-Formatter : Object reference not set to an instance of an object.
At Test-Formatter.ps1:17 char:1+Invoke-Formatter-ScriptDefinition $scriptDefinition-Settings $setti ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Invoke-Formatter], NullReferenceException
+ FullyQualifiedErrorId : RULE_ERROR,Microsoft.Windows.PowerShell.ScriptAnalyzer.Commands.InvokeFormatterCommand
$Hashtable=@{
KeyName='test1'$Object.Property='test2'
}
Error Object
$error[0] | Select-Object *
writeErrorStream : True
PSMessageDetails :
Exception : System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.AlignAssignmentStatement.HasPropertie
sOnSeparateLines(IEnumerable`1 tuples)
at Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.AlignAssignmentStatement.<FindHashtab
leViolations>d__15.MoveNext()
at Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.AlignAssignmentStatement.<AnalyzeScri
pt>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__DisplayClass78_0.<AnalyzeSynta
xTree>b__1()
TargetObject :
CategoryInfo : InvalidOperation: (:) [Invoke-Formatter], NullReferenceException
FullyQualifiedErrorId : RULE_ERROR,Microsoft.Windows.PowerShell.ScriptAnalyzer.Commands.InvokeFormatterCommand
ErrorDetails :
InvocationInfo : System.Management.Automation.InvocationInfo
ScriptStackTrace : at <ScriptBlock>, \\nas01\data\users\simon\documents\WindowsPowershell\Test-Formatter.ps1: line 16
at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo : {0, 1}
@X-Guardian Thanks for the detailed report. I just tried it and can confirm that this happens with 1.16.1 but not the latest version of the development branch and I believe this is the PR that fixed the problem that you saw. In the next days, 1.17 will be released where this should not happen any more. :-)
In the meantime you could build it yourself, if you need an urgent fix. Today I also wrote a blog post here on how to build it yourself (but the Readme has enough instructions as well). I will leave the issue for the moment for you to confirm the fix as well once the release is out if that is OK with you?
Thanks for the quick response @bergmeister. Glad to hear it is already fixed in the next release. It is actually affecting me within the VSCode PowerShell extension. Will I need to wait until the 1.17 PSScriptAnalyzer release is bundled in with vscode-powershell, or will it use a separately installed version?
The newer versions of the extension do not ship with PSSA itself any more (already a few months ago) and just use the locally installed version, therefore you will only need to update your module and vscode will start using it internally as well.
@X-Guardian PSSA 1.17.0 has been released today on the PSGallery (and attached as a zip to the release notes on GitHub). When using Install-Module, one has to specify -SkipPublisherCheck though due to signing problems with the Gallery. Can you confirm that this is fixed please?
If
Invoke-Formatter
with thePSAlignAssignmentStatementRule
enabled is run against a hashtable that contains a key name specified as an object.property, aNullReferenceException
error occurs.Steps to reproduce
Expected behavior
Return the hashtable with the assignment statements aligned:
Actual behavior
Error Object
Environment data
The text was updated successfully, but these errors were encountered: