PowerShell / PowerShell/PSScriptAnalyzer

UseCorrectCasing gets NullReferenceException from CommandInfo.get_Parameters

Ouverte
#1,708 2 commentaires 3 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Issue - Bug
Langage dominant
C#
Étoiles
2.2k
Forks
414
Merge moyen
13 h 1 min
PR mergées (30 j)
2

Description

Steps to reproduce

This reproduces about 25% of the time on my laptop. I think we may be exposing a gap in the fix for #1516, perhaps because we have about 250 .ps1 files in the repo.

Get-ChildItem *.ps1 -Recurse | % { Invoke-ScriptAnalyzer -Path $_ -Settings .\PSScriptAnalyzerSettings.psd1 }
  • If it doesn't reproduce on the first try, launch a new PowerShell window, cd into the folder, and try again.

Expected behavior

No error.

Actual behavior

Invoke-ScriptAnalyzer: Object reference not set to an instance of an object.

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 System.Management.Automation.CommandInfo.get_Parameters()
                           at Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.UseCorrectCasing.AnalyzeScript(Ast ast, String fileName)+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          : D:\code\CSS-Exchange\Diagnostics\ExchangeLogCollector\RemoteScriptBlock\IO\Copy-BulkItems.ps1
CategoryInfo          : InvalidOperation: (D:\code\CSS-Exchang…\Copy-BulkItems.ps1:String) [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
                        at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo : {0, 1}
❯ Get-Error $Error[0]

Exception             :
    Type       : System.NullReferenceException
    TargetSite :
        Name          : get_Parameters
        DeclaringType : System.Management.Automation.CommandInfo
        MemberType    : Method
        Module        : System.Management.Automation.dll
    StackTrace :
   at System.Management.Automation.CommandInfo.get_Parameters()
   at Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.UseCorrectCasing.AnalyzeScript(Ast ast, String fileName)+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()
    Message    : Object reference not set to an instance of an object.
    Source     : System.Management.Automation
    HResult    : -2147467261
TargetObject          : D:\code\CSS-Exchange\Diagnostics\ExchangeLogCollector\RemoteScriptBlock\IO\Copy-BulkItems.ps1
CategoryInfo          : InvalidOperation: (D:\code\CSS-Exchang…\Copy-BulkItems.ps1:String) [Invoke-ScriptAnalyzer], NullReferenceException
FullyQualifiedErrorId : RULE_ERROR,Microsoft.Windows.PowerShell.ScriptAnalyzer.Commands.InvokeScriptAnalyzerCommand
InvocationInfo        :
    MyCommand        : Invoke-ScriptAnalyzer
    ScriptLineNumber : 1
    OffsetInLine     : 36
    HistoryId        : 2
    Line             : Get-ChildItem *.ps1 -Recurse | % { Invoke-ScriptAnalyzer -Path $_ -Settings .\PSScriptAnalyzerSettings.psd1 }
    PositionMessage  : At line:1 char:36
                       + … curse | % { Invoke-ScriptAnalyzer -Path $_ -Settings .\PSScriptAnalyz …
                       +               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    InvocationName   : Invoke-ScriptAnalyzer
    CommandOrigin    : Internal
ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1
                        at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo :

Environment data

> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.1.3
PSEdition                      Core
GitCommitId                    7.1.3
OS                             Microsoft Windows 10.0.19043
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

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

1.19.1

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Commencez par reproduire la commande PowerShell sur le dépôt CSS-Exchange, puis examinez BuiltinRules/UseCorrectCasing et son point d’entrée AnalyzeScript mentionné dans la trace de la pile. Suivez la manière dont CommandInfo.get_Parameters est atteint et vérifiez que l’analyseur s’exécute jusqu’à son terme sans NullReferenceException sur les fichiers .ps1 de l’ensemble du dépôt.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
csharp, powershell
Domaine
devtools
Type d'issue
Bug
Difficulté
4/5
Temps estimé
3-5 jours
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
45/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.