Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

An incidentally [psobject]-wrapped strongly typed array isn't recognized as such in argument-based parameter binding #21496

Copy link
Copy link
@mklement0

Description

@mklement0
Issue body actions

Prerequisites

Steps to reproduce

Note:

# Create and import a sample cmdlet that requires [byte[]] input
Add-Type @'
using System.Management.Automation;
[Cmdlet("Get", "Foo")]
public class GetFooCommand : PSCmdlet
{
    [Parameter(Mandatory=true,ValueFromPipeline=true)]
    public byte[] InputObject;

    protected override void ProcessRecord()
    {
    }
}
'@ -PassThru | ForEach-Object Assembly | Import-Module

# Create two instances of a large byte array, one without and
# one with a [psobject] wrapper
$byteArrayUnwrapped = [byte[]]::new(64mb)
$byteArrayWrapped = New-Object byte[] 64mb  # equivalent, but with implicit [psobject] wrapper

'--- unwrapped'
Get-Foo -InputObject $byteArrayUnwrapped
'--- wrapped'
Get-Foo -InputObject $byteArrayWrapped # !! Excessively slow.
'--- done'

Note that parameter binding via the pipeline is not affected; that is,
, $byteArrayWrapped | Get-Foo works as intended (note the need to wrap $byteArrayWrapped in an aux., transitory array via the unary form of , so as to ensure that it is passed as a single object).

Expected behavior

Both calls should return virtually instantly, given that the argument type exactly matches the parameter type and that the cmdlet is otherwise a no-op.

Actual behavior

The second call, due to the invisible [psobject] wrapper resulting from use of New-Object to construct the array, takes an excessive amount of time to complete.

Error details

No response

Environment data

PowerShell 7.5.0-preview.2

Visuals

No response

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs-TriageThe issue is new and needs to be triaged by a work group.The issue is new and needs to be triaged by a work group.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.