Skip to content

Scan multiple times a module throw System.InvalidOperationException #900

Description

Steps to reproduce

Run a scan multiple times on a module :

ipmo PSScriptAnalyzer
$res=Invoke-ScriptAnalyzer-path 'C:\Program Files\WindowsPowerShell\Modules\InvokeBuild\5.1.0'

image

Expected behavior

No error.

Actual behavior

throw System.InvalidOperationException:
Collection was modified; enumeration operation may not execute.

Environment data

$psversiontable
Name Value
---------
PSVersion 5.1.14409.1012
PSEdition Desktop
PSCompatibleVersions {1.0,2.0,3.0,4.0,5.0,5.1.14409.1012}
BuildVersion 10.0.14409.1012
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.16.11.16.01.15.01.12.01.11.1

Log:

[STA] C:\temp> rver
writeErrorStream : True
PSMessageDetails :
Exception : System.Management.Automation.CmdletInvocationException: La collection a été modifiée;
l'opération d'énumération peut ne pas s'exécuter. ---> System.InvalidOperationException: La
collection a été modifiée; l'opération d'énumération peut ne pas s'exécuter.
à System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
à System.Collections.Generic.List`1.Enumerator.MoveNextRare()
à Microsoft.PowerShell.Commands.ModuleCmdletBase.UpdateCommandCollection(Collection`1 list,
List`1 patterns)
à Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadModuleManifest(String
moduleManifestPath, ExternalScriptInfo scriptInfo, Hashtable data, Hashtable localizedData,
ManifestProcessingFlags manifestProcessingFlags, Version minimumVersion, Version
maximumVersion, Version requiredVersion, Nullable`1 requiredModuleGuid, ImportModuleOptions&
options, Boolean& containedErrors)
à Microsoft.PowerShell.Commands.TestModuleManifestCommand.ProcessRecord()
à System.Management.Automation.CommandProcessor.ProcessRecord()
--- Fin de la trace de la pile d'exception interne ---
à System.Management.Automation.Runspaces.PipelineBase.Invoke(IEnumerable input)
à System.Management.Automation.PowerShell.Worker.ConstructPipelineAndDoWork(Runspace rs,
Boolean performSyncInvoke)
à System.Management.Automation.PowerShell.Worker.CreateRunspaceIfNeededAndDoWork(Runspace
rsToUse, Boolean isSync)
à
System.Management.Automation.PowerShell.CoreInvokeHelper[TInput,TOutput](PSDataCollection`1
input, PSDataCollection`1 output, PSInvocationSettings settings)
à System.Management.Automation.PowerShell.CoreInvoke[TInput,TOutput](PSDataCollection`1
input, PSDataCollection`1 output, PSInvocationSettings settings)
à System.Management.Automation.PowerShell.Invoke(IEnumerable input, PSInvocationSettings
settings)
à Microsoft.Windows.PowerShell.ScriptAnalyzer.Helper.GetModuleManifest(String filePath,
IEnumerable`1& errorRecord)
à Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.MissingModuleManifestField.<Analy
zeScript>d__0.MoveNext()
à System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
à System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
à Microsoft.Windows.PowerShell.ScriptAnalyzer.ScriptAnalyzer.<>c__DisplayClass78_0.<AnalyzeS
yntaxTree>b__1()
TargetObject : C:\Program Files\WindowsPowerShell\Modules\InvokeBuild\5.1.0\InvokeBuild.psd1
CategoryInfo : InvalidOperation: (C:\Program File...nvokeBuild.psd1:String) [Invoke-ScriptAnalyzer],
CmdletInvocationException
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}
MyCommand : Invoke-ScriptAnalyzer
BoundParameters : {}
UnboundArguments : {}
ScriptLineNumber : 1
OffsetInLine : 6
HistoryId : 9
ScriptName :
Line : $res=Invoke-ScriptAnalyzer -path 'C:\Program
Files\WindowsPowerShell\Modules\InvokeBuild\5.1.0'
PositionMessage : At line:1 char:6
+ $res=Invoke-ScriptAnalyzer -path 'C:\Program Files\WindowsPowerShell\ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
PSScriptRoot :
PSCommandPath :
InvocationName : Invoke-ScriptAnalyzer
PipelineLength : 0
PipelinePosition : 0
ExpectingInput : False
CommandOrigin : Internal
DisplayScriptPosition :
Exception at nesting level 0 ---------------------------------------------------
ErrorRecord : La collection a été modifiée ; l'opération d'énumération peut ne pas s'exécuter.
WasThrownFromThrowStatement : False
Message : La collection a été modifiée ; l'opération d'énumération peut ne pas s'exécuter.
Data : {}
InnerException : System.InvalidOperationException: La collection a été modifiée; l'opération
d'énumération peut ne pas s'exécuter.
à System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
à System.Collections.Generic.List`1.Enumerator.MoveNextRare()
à Microsoft.PowerShell.Commands.ModuleCmdletBase.UpdateCommandCollection(Collection`1
list, List`1 patterns)
à Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadModuleManifest(String
moduleManifestPath, ExternalScriptInfo scriptInfo, Hashtable data, Hashtable
localizedData, ManifestProcessingFlags manifestProcessingFlags, Version minimumVersion,
Version maximumVersion, Version requiredVersion, Nullable`1 requiredModuleGuid,
ImportModuleOptions& options, Boolean& containedErrors)
à Microsoft.PowerShell.Commands.TestModuleManifestCommand.ProcessRecord()
à System.Management.Automation.CommandProcessor.ProcessRecord()
TargetSite : System.Collections.ObjectModel.Collection`1[System.Management.Automation.PSObject]
Invoke(System.Collections.IEnumerable)
StackTrace : à System.Management.Automation.Runspaces.PipelineBase.Invoke(IEnumerable input)
à System.Management.Automation.PowerShell.Worker.ConstructPipelineAndDoWork(Runspace
rs, Boolean performSyncInvoke)
à
System.Management.Automation.PowerShell.Worker.CreateRunspaceIfNeededAndDoWork(Runspace
rsToUse, Boolean isSync)
à System.Management.Automation.PowerShell.CoreInvokeHelper[TInput,TOutput](PSDataColle
ction`1 input, PSDataCollection`1 output, PSInvocationSettings settings)
à
System.Management.Automation.PowerShell.CoreInvoke[TInput,TOutput](PSDataCollection`1
input, PSDataCollection`1 output, PSInvocationSettings settings)
à System.Management.Automation.PowerShell.Invoke(IEnumerable input,
PSInvocationSettings settings)
à Microsoft.Windows.PowerShell.ScriptAnalyzer.Helper.GetModuleManifest(String
filePath, IEnumerable`1& errorRecord)
à Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.MissingModuleManifestField.
<AnalyzeScript>d__0.MoveNext()
à System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
à System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
à Microsoft.Windows.PowerShell.ScriptAnalyzer.ScriptAnalyzer.<>c__DisplayClass78_0.<An
alyzeSyntaxTree>b__1()
HelpLink :
Source : System.Management.Automation
HResult : -2146233087
Exception at nesting level 1 ---------------------------------------------------
Message : La collection a été modifiée ; l'opération d'énumération peut ne pas s'exécuter.
Data : {}
InnerException :
TargetSite : Void ThrowInvalidOperationException(System.ExceptionResource)
StackTrace : à System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
à System.Collections.Generic.List`1.Enumerator.MoveNextRare()
à Microsoft.PowerShell.Commands.ModuleCmdletBase.UpdateCommandCollection(Collection`1 list, List`1
patterns)
à Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadModuleManifest(String moduleManifestPath,
ExternalScriptInfo scriptInfo, Hashtable data, Hashtable localizedData, ManifestProcessingFlags
manifestProcessingFlags, Version minimumVersion, Version maximumVersion, Version requiredVersion,
Nullable`1 requiredModuleGuid, ImportModuleOptions& options, Boolean& containedErrors)
à Microsoft.PowerShell.Commands.TestModuleManifestCommand.ProcessRecord()
à System.Management.Automation.CommandProcessor.ProcessRecord()
HelpLink :
Source : mscorlib
HResult : -2146233079
[STA] C:\temp> $stacktrace
à System.Management.Automation.AuthorizationManager.ShouldRunInternal(CommandInfo commandInfo, CommandOrigin origin,
PSHost host)
à System.Management.Automation.CommandDiscovery.ShouldRun(ExecutionContext context, PSHost host, CommandInfo commandI
nfo, CommandOrigin commandOrigin)
à System.Management.Automation.CommandDiscovery.LookupCommandProcessor(CommandInfo commandInfo, CommandOrigin command
Origin, Nullable`1 useLocalScope, SessionStateInternal sessionState)
à System.Management.Automation.CommandDiscovery.LookupCommandProcessor(String commandName, CommandOrigin commandOrigi
n, Nullable`1 useLocalScope)
à System.Management.Automation.ExecutionContext.CreateCommand(String command, Boolean dotSource)
à System.Management.Automation.PipelineOps.AddCommand(PipelineProcessor pipe, CommandParameterInternal[] commandEleme
nts, CommandBaseAst commandBaseAst, CommandRedirection[] redirections, ExecutionContext context)
à System.Management.Automation.PipelineOps.InvokePipeline(Object input, Boolean ignoreInput, CommandParameterInternal
[][] pipeElements, CommandBaseAst[] pipeElementAsts, CommandRedirection[][] commandRedirections, FunctionContext funcCon
text)
à System.Management.Automation.Interpreter.ActionCallInstruction`6.Run(InterpretedFrame frame)
à System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions