-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Open
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.
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
Note:
- This is yet another manifestation of Objects are situationally invisibly [psobject]-wrapped, sometimes causing unexpected behavior. #5579
# 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.2Visuals
No response
Metadata
Metadata
Assignees
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.