-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Closed
Labels
Resolution-FixedThe issue is fixed.The issue is fixed.
Description
Prerequisites
- Write a descriptive title.
- Make sure you are able to repro it on the latest released version
- Search the existing issues.
- Refer to the FAQ.
- Refer to Differences between Windows PowerShell 5.1 and PowerShell.
Steps to reproduce
- Save this function to file, add it to a module, and export it: https://gist.github.com/fmotion1/0a0709c8f09df92a6ca7a5744de88324
- Create a new script, and define a
ForEach-Object -Parallelblock that will run more than once - ideally feeding the script block with images. I'm using this: https://gist.github.com/fmotion1/cd690cad6cc5ed6eac245ab16f8196c6 - Hopefully you get the same error I do:
ErrorRecord : The 'Get-ImageDimensions' command was found in the module 'VSYSFileOps', but
the module could not be loaded due to the following error: [An item with the
same key has already been added. Key: 1617118572]
For more information, run 'Import-Module VSYSFileOps'.
CommandName : Get-ImageDimensions
WasThrownFromThrowStatement : True
TargetSite : Void
CheckActionPreference(System.Management.Automation.Language.FunctionContext,
System.Exception)
Message : The 'Get-ImageDimensions' command was found in the module 'VSYSFileOps', but
the module could not be loaded due to the following error: [An item with the
same key has already been added. Key: 1617118572]
For more information, run 'Import-Module VSYSFileOps'.
Data : {[System.Management.Automation.Interpreter.InterpretedFrameInfo,
System.Management.Automation.Interpreter.InterpretedFrameInfo[]]}
InnerException : System.Management.Automation.CmdletInvocationException: An item with the same
key has already been added. Key: 1617118572
---> System.ArgumentException: An item with the same key has already been
added. Key: 1617118572
at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue
value, InsertionBehavior behavior)
at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
at
Microsoft.PowerShell.Commands.AddTypeCommand.DoEmitAndLoadAssembly(Compilation
compilation, EmitOptions emitOptions)
at Microsoft.PowerShell.Commands.AddTypeCommand.SourceCodeProcessing()
at System.Management.Automation.CommandProcessorBase.Complete()
--- End of inner exception stack trace ---
at System.Management.Automation.Runspaces.PipelineBase.Invoke(IEnumerable
input)
at System.Management.Automation.PowerShell.Worker.ConstructPipelineAndDoWork
(Runspace rs, Boolean performSyncInvoke)
at System.Management.Automation.PowerShell.CoreInvokeHelper[TInput,TOutput](
PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings
settings)
at System.Management.Automation.PowerShell.CoreInvoke[TInput,TOutput](PSData
Collection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)
at System.Management.Automation.PowerShell.Invoke[T]()
at
System.Management.Automation.CommandDiscovery.AutoloadSpecifiedModule(String
moduleName, ExecutionContext context, SessionStateEntryVisibility visibility,
Exception& exception)
HelpLink :
Source : System.Management.Automation
HResult : -2146233087
StackTrace : at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(F
unctionContext funcContext, Exception exception)
at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(Inte
rpretedFrame frame)
at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.
Run(InterpretedFrame frame)
at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.
Run(InterpretedFrame frame)
at
System.Management.Automation.Interpreter.Interpreter.Run(InterpretedFrame
frame)
at System.Management.Automation.Interpreter.LightLambda.RunVoid1[T0](T0
arg0)
at
System.Management.Automation.DlrScriptCommandProcessor.RunClause(Action`1
clause, Object dollarUnderbar, Object inputToProcess)
--- End of stack trace from previous location ---
at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecut
eEnumerate(Object input)
at System.Management.Automation.Runspaces.LocalPipeline.InvokeHelper()
at System.Management.Automation.Runspaces.LocalPipeline.InvokeThreadProc()
Exception: The 'Get-ImageDimensions' command was found in the module 'VSYSFileOps',
but the module could not be loaded due to the following error: [An item with the same
key has already been added. Key: 1617118572]
For more information, run 'Import-Module VSYSFileOps'.Expected behavior
Image dimensions are returned for all images piped into the ForEach-Object -parallel block.Actual behavior
Powershell explodes. Unpredictably too.
I created another script:
$Files = "D:\TestImages\512_solus.png", "D:\TestImages\512_suse.png", "D:\TestImages\512_tails.png"
$Files | ForEach-Object -Parallel {
$Image = $_
try {
$Dimensions = Get-ImageDimensions($Image)
Write-Host "`$Dimensions.Width:" $Dimensions.Width -ForegroundColor Green
Write-Host "`$Dimensions.Height:" $Dimensions.Height -ForegroundColor Green
} catch {
$Error[0].Exception
}
} -ThrottleLimit 16
And when I run this, I don't get the error. But I do get it when I run the initial script in the gist.Error details
Get-Error
Exception :
Type : System.Management.Automation.CommandNotFoundException
ErrorRecord :
Exception :
Type : System.Management.Automation.ParentContainsErrorRecordException
Message : The 'Get-ImageDimensions' command was found in the module 'VSYSFileOps', but the
module could not be loaded due to the following error: [An item with the same key has already been added.
Key: -1283599215]
For more information, run 'Import-Module VSYSFileOps'.
HResult : -2146233087
TargetObject : Get-ImageDimensions
CategoryInfo : ObjectNotFound: (Get-ImageDimensions:String) [],
ParentContainsErrorRecordException
FullyQualifiedErrorId : CouldNotAutoloadMatchingModule
InvocationInfo :
ScriptLineNumber : 24
OffsetInLine : 27
HistoryId : 1
Line : $Dimensions = Get-ImageDimensions($Image)
PositionMessage : At line:24 char:27
+ $Dimensions = Get-ImageDimensions($Image)
+ ~~~~~~~~~~~~~~~~~~~
InvocationName : Get-ImageDimensions
CommandOrigin : Internal
ScriptStackTrace : at <ScriptBlock>, <No file>: line 24
CommandName : Get-ImageDimensions
WasThrownFromThrowStatement : True
TargetSite :
Name : CheckActionPreference
DeclaringType : System.Management.Automation.ExceptionHandlingOps, System.Management.Automation,
Version=7.3.6.500, Culture=neutral, PublicKeyToken=31bf3856ad364e35
MemberType : Method
Module : System.Management.Automation.dll
Message : The 'Get-ImageDimensions' command was found in the module 'VSYSFileOps',
but the module could not be loaded due to the following error: [An item with the same key has already been
added. Key: -1283599215]
For more information, run 'Import-Module VSYSFileOps'.
Data : System.Collections.ListDictionaryInternal
InnerException :
Type : System.Management.Automation.CmdletInvocationException
ErrorRecord :
Exception :
Type : System.ArgumentException
Message : An item with the same key has already been added. Key: -1283599215
TargetSite :
Name : ThrowAddingDuplicateWithKeyArgumentException
DeclaringType : System.ThrowHelper, System.Private.CoreLib, Version=7.0.0.0,
Culture=neutral, PublicKeyToken=7cec85d7bea7798e
MemberType : Method
Module : System.Private.CoreLib.dll
Source : System.Private.CoreLib
HResult : -2147024809
StackTrace :
at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
at Microsoft.PowerShell.Commands.AddTypeCommand.DoEmitAndLoadAssembly(Compilation compilation,
EmitOptions emitOptions)
at Microsoft.PowerShell.Commands.AddTypeCommand.SourceCodeProcessing()
at System.Management.Automation.CommandProcessorBase.Complete()
CategoryInfo : NotSpecified: (:) [Import-Module], ArgumentException
FullyQualifiedErrorId :
System.ArgumentException,Microsoft.PowerShell.Commands.ImportModuleCommand
InvocationInfo :
MyCommand : Import-Module
HistoryId : 1
InvocationName : Import-Module
CommandOrigin : Internal
ScriptStackTrace : at <ScriptBlock>,
D:\Dev\Powershell\VSYSModules\VSYSFileOps\Public\Get-FilePathComponents.ps1: line 14
at <ScriptBlock>,
D:\Dev\Powershell\VSYSModules\VSYSFileOps\VSYSFileOps.psm1: line 6
at <ScriptBlock>, <No file>: line 24
PipelineIterationInfo :
TargetSite :
Name : Invoke
DeclaringType : System.Management.Automation.Runspaces.PipelineBase,
System.Management.Automation, Version=7.3.6.500, Culture=neutral, PublicKeyToken=31bf3856ad364e35
MemberType : Method
Module : System.Management.Automation.dll
Message : An item with the same key has already been added. Key: -1283599215
InnerException :
Type : System.ArgumentException
Message : An item with the same key has already been added. Key: -1283599215
TargetSite :
Name : ThrowAddingDuplicateWithKeyArgumentException
DeclaringType : System.ThrowHelper, System.Private.CoreLib, Version=7.0.0.0,
Culture=neutral, PublicKeyToken=7cec85d7bea7798e
MemberType : Method
Module : System.Private.CoreLib.dll
Source : System.Private.CoreLib
HResult : -2147024809
StackTrace :
at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
at Microsoft.PowerShell.Commands.AddTypeCommand.DoEmitAndLoadAssembly(Compilation compilation,
EmitOptions emitOptions)
at Microsoft.PowerShell.Commands.AddTypeCommand.SourceCodeProcessing()
at System.Management.Automation.CommandProcessorBase.Complete()
Source : System.Management.Automation
HResult : -2146233087
StackTrace :
at System.Management.Automation.Runspaces.PipelineBase.Invoke(IEnumerable input)
at System.Management.Automation.PowerShell.Worker.ConstructPipelineAndDoWork(Runspace rs, Boolean
performSyncInvoke)
at System.Management.Automation.PowerShell.CoreInvokeHelper[TInput,TOutput](PSDataCollection`1 input,
PSDataCollection`1 output, PSInvocationSettings settings)
at System.Management.Automation.PowerShell.CoreInvoke[TInput,TOutput](PSDataCollection`1 input,
PSDataCollection`1 output, PSInvocationSettings settings)
at System.Management.Automation.PowerShell.Invoke[T]()
at System.Management.Automation.CommandDiscovery.AutoloadSpecifiedModule(String moduleName,
ExecutionContext context, SessionStateEntryVisibility visibility, Exception& exception)
Source : System.Management.Automation
HResult : -2146233087
StackTrace :
at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext,
Exception exception)
at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
at System.Management.Automation.Interpreter.Interpreter.Run(InterpretedFrame frame)
at System.Management.Automation.Interpreter.LightLambda.RunVoid1[T0](T0 arg0)
at System.Management.Automation.DlrScriptCommandProcessor.RunClause(Action`1 clause, Object
dollarUnderbar, Object inputToProcess)
--- End of stack trace from previous location ---
at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(Object input)
at System.Management.Automation.Runspaces.LocalPipeline.InvokeHelper()
at System.Management.Automation.Runspaces.LocalPipeline.InvokeThreadProc()
TargetObject : System.Management.Automation.PSTasks.PSTask
CategoryInfo : InvalidOperation: (System.Management.A…tion.PSTasks.PSTask:PSTask) [],
CommandNotFoundException
FullyQualifiedErrorId : PSTaskExceptionEnvironment data
Name Value
---- -----
PSVersion 7.3.6
PSEdition Core
GitCommitId 7.3.6
OS Microsoft Windows 10.0.19045
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0Visuals
No response
Metadata
Metadata
Assignees
Labels
Resolution-FixedThe issue is fixed.The issue is fixed.