Skip to content

(Dynamic) Parameter Sets are limited to 32 entries #10447

Closed

Description

While developing custom assertions in Pester, I ran into an issue after adding more and more custom assertions . After adding the overall 33th asserting, this leads to a 33th dynamic parameter set, the parameter binding within PowerShell does not work as expected. The first parameter set gets somehow connected to the 33th parameter set. As there is an internal cache for 32 parameter sets which has an overflow.

Steps to reproduce

# Up to 32 entries, it works. Starting with 33 it will not work anymore
$count = 32

function Test-DynamicParam
{
    # Remove the cmdlet binding, so not using an advanced funtion, all is fine
    [CmdletBinding()]
    param ()

    dynamicparam
    {
        $parameterDictionary = New-Object System.Management.Automation.RuntimeDefinedParameterDictionary
        for ($i = 0; $i -lt $count; $i++) {
            $name = "Demo$i"
            $attribute = New-Object Management.Automation.ParameterAttribute
            $attribute.ParameterSetName = $name
            $attribute.Position = $i
            $attribute.Mandatory = $true
            $attributeCollection = New-Object System.Collections.ObjectModel.Collection[System.Attribute]
            $attributeCollection.Add($attribute)
            $parameter = New-Object System.Management.Automation.RuntimeDefinedParameter($name, [System.Boolean], $attributeCollection)
            $parameterDictionary.Add($name, $parameter)
        }
        return $parameterDictionary
    }
}

for ($i = 0; $i -lt $count; $i++) {
    $parameterSplat = @{
        "Demo$i" = $true
    }
    Write-Host "Test-DynamicParam -Demo$i"
    Test-DynamicParam @parameterSplat
}

Expected behavior

Every parameter set works for itself.

PS C:\> .\pester-issue.ps1 
Test-DynamicParam -Demo0                                                                                                Test-Test-DynamicParam -Demo1
Test-DynamicParam -Demo2
Test-DynamicParam -Demo3
Test-DynamicParam -Demo4
Test-DynamicParam -Demo5
Test-DynamicParam -Demo6
Test-DynamicParam -Demo7
Test-DynamicParam -Demo8
Test-DynamicParam -Demo9
Test-DynamicParam -Demo10
Test-DynamicParam -Demo11
Test-DynamicParam -Demo12
Test-DynamicParam -Demo13
Test-DynamicParam -Demo14
Test-DynamicParam -Demo15
Test-DynamicParam -Demo16
Test-DynamicParam -Demo17
Test-DynamicParam -Demo18
Test-DynamicParam -Demo19
Test-DynamicParam -Demo20
Test-DynamicParam -Demo21
Test-DynamicParam -Demo22
Test-DynamicParam -Demo23
Test-DynamicParam -Demo24
Test-DynamicParam -Demo25
Test-DynamicParam -Demo26
Test-DynamicParam -Demo27
Test-DynamicParam -Demo28
Test-DynamicParam -Demo29
Test-DynamicParam -Demo30
Test-DynamicParam -Demo31
Test-DynamicParam -Demo32

Actual behavior

The 1st (-Demo0) is connected to the 33th (-Demo32).

PS C:\> .\pester-issue.ps1 
Test-DynamicParam -Demo0                                                                                                

cmdlet Test-DynamicParam at command pipeline position 1
Supply values for the following parameters:
Demo32:

Environment data

Name                           Value
----                           -----
PSVersion                      6.2.2
PSEdition                      Core
GitCommitId                    6.2.2
OS                             Microsoft Windows 10.0.18362
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Activity

  1. added
    Issue-Question
    on Aug 26, 2019
  2. iSazonov commented on Aug 27, 2019

    @iSazonov
    Collaborator

    Claudio Spizzi (@claudiospizzi) Thanks for you report!

    It is dup #9372

    /cc Jason Shirk (@lzybkr) You might be interested to see this use case.

  3. vexx32 commented on Aug 27, 2019

    @vexx32
    Collaborator

    I think you meant #9372? Though that doesn't specifically mention dynamic parameters; it seems the limitation is a hard limit for all parameters.

  4. iSazonov commented on Aug 27, 2019

    @iSazonov
    Collaborator

    Rain Sallow (/u/ta11ow) (@vexx32) Thanks! It was copy-paste error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-QuestionResolution-Duplicate

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions