GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(engine): unwrap scalar PSObject during collection binding by daksh-goyal · Pull Request #27970 · PowerShell/PowerShell

Conversation

@daksh-goyal

@daksh-goyal Daksh Goyal (daksh-goyal) commented Sep 3, 2026

Copy link
Copy Markdown

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

  • PR has a meaningful title
    • Use the present tense and imperative mood when describing your changes
  • Summarized changes
  • Make sure all .h, .cpp, .cs, .ps1 and .psm1 files have the correct copyright header
  • This PR is ready to merge. If this PR is a work in progress, please open this as a Draft Pull Request and mark it as Ready to Review when it is ready to merge.
  • Breaking changes
    • None
    • OR
    • Experimental feature(s) needed
      • Experimental feature name(s):
  • User-facing changes
    • Not Applicable
    • OR
    • Documentation needed
      • [] Issue filed:
  • Testing - New and feature
    • N/A or can only be tested interactively
    • OR
    • Make sure you've added a new test if existing tests do not effectively test the code changed

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@daksh-goyal
fix(engine): unwrap scalar PSObject during collection binding
5a27c75
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.
@daksh-goyal
Daksh Goyal (daksh-goyal) requested a review from a team as a code owner September 3, 2026 21:28
Copilot AI lite review requested due to automatic review settings September 3, 2026 21:28
@azure-pipelines

azure-pipelines Bot commented Sep 3, 2026

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Copilot started reviewing on behalf of Daksh Goyal (daksh-goyal) September 3, 2026 21:29
View session
Copilot AI reviewed Sep 3, 2026
View reviewed changes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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 in ParameterBinderBase.EncodeCollection.
  • Add a regression Pester test that reproduces the failure shape using a StringCollection parameter and a single pipeline-produced scalar value.
File summaries
File Description
test/powershell/Language/Parser/ParameterBinding.Tests.ps1 Adds regression coverage for binding a scalar pipeline-produced PSObject to StringCollection.
src/System.Management.Automation/engine/ParameterBinderBase.cs Unwraps scalar PSObject values prior to collection insertion to avoid invalid casts and align with element-binding behavior.
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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@microsoft-github-policy-service microsoft-github-policy-service Bot added the Review - Needed The PR is being reviewed label Sep 25, 2026
@microsoft-github-policy-service

microsoft-github-policy-service Bot commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days.
Maintainer, please provide feedback and/or mark it as Waiting on Author

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

daxian-dbw
Dongbo Wang (daxian-dbw) reviewed Oct 5, 2026
View reviewed changes
Comment thread src/System.Management.Automation/engine/ParameterBinderBase.cs
"Argument type {0} is not IList, treating this as scalar",
currentValue.GetType().Name);

object currentValueElement = PSObject.Base(currentValue);

@daxian-dbw Dongbo Wang (daxian-dbw) Oct 5, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This applies to every collection type, and that is too broad. It's better to special case the StringCollection type as the WG comment pointed out in the issue.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@daxian-dbw

Dongbo Wang (daxian-dbw) commented Oct 5, 2026

Copy link
Copy Markdown
Member

This PR is superseded by #28141

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@daxian-dbw Dongbo Wang (daxian-dbw) closed this Oct 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@daxian-dbw Dongbo Wang (daxian-dbw) daxian-dbw left review comments
Copilot code review Copilot
Copilot review effort
Applies to this pull request for everyone.Learn more about Copilot code review.
Copilot left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

Review - Needed The PR is being reviewed

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Binary cmdlet binding fails to unwrap a scalar PSObject for StringCollection parameters

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@daksh-goyal @daxian-dbw
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.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.