{{ message }}
fix(engine): unwrap scalar PSObject during collection binding - #27970
Open
Daksh Goyal (daksh-goyal) wants to merge 1 commit into
Open
fix(engine): unwrap scalar PSObject during collection binding#27970Daksh Goyal (daksh-goyal) wants to merge 1 commit into
Daksh Goyal (daksh-goyal) wants to merge 1 commit into
Conversation
Unwrap scalar values before adding them to collection parameters, matching the existing behavior for list elements. This prevents StringCollection parameters from attempting to cast a PSObject directly to a string. Add regression coverage for a single pipeline-produced value.
Copilot started reviewing on behalf of
Daksh Goyal (daksh-goyal)
September 3, 2026 21:29
View session
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The binding fix is targeted and low-risk, and it is backed by a focused regression test covering the reported failure scenario.
Pull request overview
This PR fixes a parameter-binding edge case where a scalar PSObject (wrapping a string) was added directly to non-generic IList-backed collection parameters (e.g., StringCollection), causing invalid casts; it now unwraps the scalar value first, matching existing behavior for list elements.
Changes:
- Unwrap scalar values via
PSObject.Base(...)before adding them to collection parameters inParameterBinderBase.EncodeCollection. - Add a regression Pester test that reproduces the failure shape using a
StringCollectionparameter and a single pipeline-produced scalar value.
File summaries
Review details
Suppressed comments (1)
src/System.Management.Automation/engine/ParameterBinderBase.cs:1827
- The binding tracer format string uses
{1}but only supplies a single argument, so traces will literally print{1}instead of the element type. This makes diagnosing coercion-required cases harder.
if (currentValueElementType != desiredElementType &&
!currentValueElementType.IsSubclassOf(desiredElementType))
{
bindingTracer.WriteLine(
"COERCION REQUIRED: Did not coerce scalar arg value to type {1}",
- Files reviewed: 2/2 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

PR Summary
Unwrap scalar values before adding them to collection parameters, matching the existing behavior for list elements. This prevents StringCollection parameters from attempting to cast a PSObject directly to a string.
Add regression coverage for a single pipeline-produced value.
PR Context
fixes #27969
PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright header