Skip to content
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

NullReferenceException in PSAvoidAssignmentToAutomaticVariable rule when assigning .Net property to .Net property (v 1.17.0) #1007

Closed
bergmeister opened this issue Jun 2, 2018 · 1 comment · Fixed by #1008
Assignees
Milestone

Comments

@bergmeister
Copy link
Collaborator

Thanks to @lipkau for the initial bug report in Slack.

Steps to reproduce

Invoke-ScriptAnalyzer -ScriptDefinition '[foo]::bar = [baz]::qux'

Expected behavior

Normal behaviour, no warnings.

Actual behavior

Invoke-ScriptAnalyzer : Object reference not set to an instance of an object.
At line:1 char:2
+  Invoke-ScriptAnalyzer -ScriptDefinition '[foo]::SecurityProtocol = [ ...
+  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Invoke-ScriptAnalyzer], NullReferenceException
    + FullyQualifiedErrorId : RULE_ERROR,Microsoft.Windows.PowerShell.ScriptAnalyzer.Commands.InvokeScriptAnalyzerCommand

If an unexpected error was thrown then please report the full error details using e.g. $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.AvoidAssignmentToAutomaticVariable.<AnalyzeScript>d__2.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__DisplayClass82_1.<AnalyzeSyntaxTree>b__2()
TargetObject          :
CategoryInfo          : InvalidOperation: (:) [Invoke-ScriptAnalyzer], NullReferenceException
FullyQualifiedErrorId : RULE_ERROR,Microsoft.Windows.PowerShell.ScriptAnalyzer.Commands.InvokeScriptAnalyzerCommand
ErrorDetails          :
InvocationInfo        : System.Management.Automation.InvocationInfo
ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo : {0, 1}
writeErrorStream      : True
PSMessageDetails      :
Exception             : System.NullReferenceException: Object reference not set to an instance of an object.
                           at Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.AvoidAssignmentToAutomaticVariable.<AnalyzeScript>d__2.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__DisplayClass82_1.<AnalyzeSyntaxTree>b__2()
TargetObject          :
CategoryInfo          : InvalidOperation: (:) [Invoke-ScriptAnalyzer], NullReferenceException
FullyQualifiedErrorId : RULE_ERROR,Microsoft.Windows.PowerShell.ScriptAnalyzer.Commands.InvokeScriptAnalyzerCommand
ErrorDetails          :
InvocationInfo        : System.Management.Automation.InvocationInfo
ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo : {0, 1}

Environment data

This bug was introduced in 1.17.0 in the new PSAvoidAssignmentToAutomaticVariable

> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      5.1.17134.81
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.17134.81
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.17.0
@bergmeister
Copy link
Collaborator Author

@lipkau The fix of this has been released as part of the new 1.17.1 release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment