Binary cmdlet binding fails to unwrap a scalar PSObject for StringCollection parameters
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 58/100
Direzione di ricerca
Inizia con ParameterBinderBase.EncodeCollection, indicato nello stack trace, e riproduci il problema con lo script PowerShell nel report. Confronta il caso PSObject scalare con l'array di stringhe e i controlli con risultati multipli; il lavoro è completato quando il caso scalare viene associato a StringCollection e restituisce il valore previsto senza rompere i controlli.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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
$source = @'
using System.Collections.Specialized;
using System.Management.Automation;
[Cmdlet("Test", "StringCollectionBinding")]
public sealed class TestStringCollectionBindingCommand : PSCmdlet
{
[Parameter(Mandatory = true)]
public StringCollection Value { get; set; }
protected override void ProcessRecord()
{
WriteObject(Value[0]);
}
}
'@
$type = Add-Type -TypeDefinition $source -PassThru
Import-Module -Assembly $type.Assembly
# Select-Object emits one scalar PSObject wrapping a string.
$value = 'test-value' | Select-Object -Unique
$value.GetType().FullName
$value -is [System.Management.Automation.PSObject]
Test-StringCollectionBinding -Value $value
# The control case succeeds:
Test-StringCollectionBinding -Value ([string[]]$value)
# Multiple pipeline results also succeed:
$values = 'first', 'second' | Select-Object -Unique
Test-StringCollectionBinding -Value $values
Expected behavior
System.String
True
test-value
Actual behavior
System.String
True
Test-StringCollectionBinding:
Cannot convert 'expected' to the type
'System.Collections.Specialized.StringCollection' required by parameter
'Value'. Unable to cast object of type
'System.Management.Automation.PSObject' to type 'System.String'.
Error details
Exception :
Type : System.Management.Automation.ParameterBindingException
Message : Cannot convert 'test-value' to the type 'System.Collections.Specialized.StringCollection' required by parameter 'Value'. Unable to cast object of type 'System.Management.Automation.PSObject' to type 'System.String'.
ParameterName : Value
ParameterType : [System.Collections.Specialized.StringCollection]
TypeSpecified : [System.Management.Automation.PSObject]
ErrorId : CannotConvertArgument
Line : 22
Offset : 37
CommandInvocation :
MyCommand : Test-StringCollectionBinding
ScriptLineNumber : 22
OffsetInLine : 1
HistoryId : 1
Line : Test-StringCollectionBinding -Value $value 2>$null
Statement : Test-StringCollectionBinding -Value $value 2>$null
PositionMessage : At line:22 char:1
+ Test-StringCollectionBinding -Value $value 2>$null
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
InvocationName : Test-StringCollectionBinding
PipelineLength : 1
PipelinePosition : 1
ErrorRecord :
Exception :
Type : System.Management.Automation.ParentContainsErrorRecordException
Message : Cannot convert 'test-value' to the type 'System.Collections.Specialized.StringCollection' required by parameter 'Value'. Unable to cast object of type 'System.Management.Automation.PSObject' to type 'System.String'.
HResult : -2146233087
CategoryInfo : InvalidArgument: (:) [Test-StringCollectionBinding], ParentContainsErrorRecordException
FullyQualifiedErrorId : CannotConvertArgument,TestStringCollectionBindingCommand
InvocationInfo :
MyCommand : Test-StringCollectionBinding
ScriptLineNumber : 22
OffsetInLine : 37
HistoryId : 1
Line : Test-StringCollectionBinding -Value $value 2>$null
Statement : $value
PositionMessage : At line:22 char:37
+ Test-StringCollectionBinding -Value $value 2>$null
+ ~~~~~~
CommandOrigin : Internal
ScriptStackTrace : at <ScriptBlock>, <No file>: line 22
TargetSite :
Name : EncodeCollection
DeclaringType : [System.Management.Automation.ParameterBinderBase]
MemberType : Method
Module : System.Management.Automation.dll
Data :
System.Management.Automation.Interpreter.InterpretedFrameInfo, System.Management.Automation, Version=7.6.0.500, Culture=neutral, PublicKeyToken=31bf3856ad364e35 : <ScriptBlock>
InnerException :
Type : System.InvalidCastException
TargetSite :
Name : ChkCastAny_NoCacheLookup
DeclaringType : [System.Runtime.CompilerServices.CastHelpers]
MemberType : Method
Module : System.Private.CoreLib.dll
Message : Unable to cast object of type 'System.Management.Automation.PSObject' to type 'System.String'.
Source : System.Private.CoreLib
HResult : -2147467262
StackTrace :
at System.Collections.Specialized.StringCollection.System.Collections.IList.Add(Object value)
at System.Management.Automation.ParameterBinderBase.EncodeCollection(CommandParameterInternal argument, String parameterName, ParameterCollectionTypeInformation collectionTypeInformation, Type toType, Object currentValue, Boolean
coerceElementTypeIfNeeded, Boolean& coercionRequired)
Source : System.Management.Automation
HResult : -2146233087
StackTrace :
at System.Management.Automation.ParameterBinderBase.EncodeCollection(CommandParameterInternal argument, String parameterName, ParameterCollectionTypeInformation collectionTypeInformation, Type toType, Object currentValue, Boolean
coerceElementTypeIfNeeded, Boolean& coercionRequired)
at System.Management.Automation.ParameterBinderBase.CoerceTypeAsNeeded(CommandParameterInternal argument, String parameterName, Type toType, ParameterCollectionTypeInformation collectionTypeInfo, Object currentValue)
at System.Management.Automation.ParameterBinderBase.BindParameter(CommandParameterInternal parameter, CompiledCommandParameter parameterMetadata, ParameterBindingFlags flags)
at System.Management.Automation.CmdletParameterBinderController.BindParameter(CommandParameterInternal argument, MergedCompiledCommandParameter parameter, ParameterBindingFlags flags)
at System.Management.Automation.CmdletParameterBinderController.BindParameter(UInt32 parameterSets, CommandParameterInternal argument, MergedCompiledCommandParameter parameter, ParameterBindingFlags flags)
at System.Management.Automation.CmdletParameterBinderController.BindNamedParameter(UInt32 parameterSets, CommandParameterInternal argument, MergedCompiledCommandParameter parameter)
at System.Management.Automation.ParameterBinderController.BindNamedParameters(UInt32 parameterSets, Collection`1 arguments)
at System.Management.Automation.CmdletParameterBinderController.BindCommandLineParametersNoValidation(Collection`1 arguments)
at System.Management.Automation.CmdletParameterBinderController.BindCommandLineParameters(Collection`1 arguments)
at System.Management.Automation.CommandProcessor.BindCommandLineParameters()
at System.Management.Automation.CommandProcessor.Prepare(IDictionary psDefaultParameterValues)
at System.Management.Automation.CommandProcessorBase.DoPrepare(IDictionary psDefaultParameterValues)
at System.Management.Automation.Internal.PipelineProcessor.Start(Boolean incomingStream)
at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(Object input)
--- End of stack trace from previous location ---
at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(Object input)
at System.Management.Automation.PipelineOps.InvokePipeline(Object input, Boolean ignoreInput, CommandParameterInternal[][] pipeElements, CommandBaseAst[] pipeElementAsts, CommandRedirection[][] commandRedirections, FunctionContext
funcContext)
at System.Management.Automation.Interpreter.ActionCallInstruction`6.Run(InterpretedFrame frame)
at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
CategoryInfo : InvalidArgument: (:) [Test-StringCollectionBinding], ParameterBindingException
FullyQualifiedErrorId : CannotConvertArgument,TestStringCollectionBindingCommand
InvocationInfo :
MyCommand : Test-StringCollectionBinding
ScriptLineNumber : 22
OffsetInLine : 37
HistoryId : 1
Line : Test-StringCollectionBinding -Value $value 2>$null
Statement : $value
PositionMessage : At line:22 char:37
+ Test-StringCollectionBinding -Value $value 2>$null
+ ~~~~~~
CommandOrigin : Internal
ScriptStackTrace : at <ScriptBlock>, <No file>: line 22
Environment data
Name Value
---- -----
PSVersion 7.6.5
PSEdition Core
GitCommitId 7.6.5
OS Microsoft Windows 10.0.26200
Platform Win32NT
PSRemotingProtocolVersion 2.4
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Visuals
No response
- Lingua principale
- C#
- Stelle
- 55.5k
- Fork
- 8.5k
- Merge medio
- 1g 35m
- PR unite (30g)
- 136
Preparare l'ambiente
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di PowerShell/PowerShell
-
Issue-Enhancement Needs-Triage WG-Cmdlets
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 86/100
PowerShell/PowerShell#28061 · 2 commenti · 3 reazioni ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
PowerShell/PowerShell#28037 ·
I maintainer di solito rispondono entro 1 giorno
-
Needs-Triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
PowerShell/PowerShell#27973 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
PowerShell/PowerShell#27720 ·
I maintainer di solito rispondono entro 1 giorno
-
Issue-Bug Up-for-Grabs WG-Cmdlets WG-Reviewed
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
PowerShell/PowerShell#27670 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di PowerShell/PowerShell
Issue simili
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
fluentassertions/fluentassertions#3353 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
-
Difficoltà 2/5 Mezza giornata Idoneità per principianti 78/100
unoplatform/uno#24769 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
AvaloniaUI/Avalonia#22323 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
microsoft/onnxruntime-genai#2633 ·
I maintainer di solito rispondono entro 1 giorno