PSScriptAnalyzer: PSUseToExportFieldsInManifest throw System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
Steps to reproduce
1..30|% {$res=Invoke-ScriptAnalyzer -path 'C:\Program Files\WindowsPowerShell\Modules\PSScriptAnalyzer\1.16.1\PSScriptAnalyzer.psd1' -ExcludeRule PSMissingModuleManifestField }
Expected behavior
No error.
Actual behavior
Invoke-ScriptAnalyzer : La collection a été modifiée ; l'opération d'énumération peut ne pas s'exécuter.
At line:1 char:15
+ ... .30|% {$res=Invoke-ScriptAnalyzer -path 'C:\Program Files\WindowsPowe ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (C:\Program File...ptAnalyzer.psd1:String) [Invoke-ScriptAnalyzer], Cm
dletInvocationException
+ FullyQualifiedErrorId : RULE_ERROR,Microsoft.Windows.PowerShell.ScriptAnalyzer.Commands.InvokeScriptAnalyzerComm
and
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.1
1.16.0
1.15.0
1.12.0
1.11.1
See also the issue #900
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 19 (1 by maintainers)
I was able to reproduce, but the error does not always occur.
Update: I can finally reproduce now with a
Standard D2s v3 (2 vcpus, 8 GB memory)Azure VM (WinServer 2016). I get the error also for anotherps.Invoke()call inAvoidUsingDeprecatedManifestFieldsin addition to the one that we found before in the Helper class. I get the issue also with PowerShell Core 6.0.2. Implementing theusingpattern instead of the manual call to dispose does not fix it, therefore this rather looks like a problem of thread safety of theInvoke()method.I no longer encounter this error.
The bug here involves ALIASES as far as I can tell.
At this point, I can reproduce this easily on my laptop with an empty psm1 and a three line .psd1:
NOTE:
broken.psm1)You can actually set
AliasesToExportto"*"and then you’ll get failures of the rule mixed in with the exceptions – The rule still worksThis reproduces too:
It’s clearly a problem specific to aliases and this rule.
With Windows Seven sp1 Fr ( Microsoft Windows [version 6.1.7601] )
Issue902.txt