Home Dashboard Directory Help
Search

Parameter binding succeeds unexpectedly with ValueFromPipelineByPropertyName by Tom Nolan [MSFT]


Status: 

Closed
 as Not Reproducible Help for as Not Reproducible


1
0
Sign in
to vote
Type: Bug
ID: 787076
Opened: 5/16/2013 9:27:11 AM
Access Restriction: Public
0
Workaround(s)
view
1
User(s) can reproduce this bug

Description



[edited to reflect an issue in my sample]
This refers to creating an advanced function or cmdlet with different parameter sets where the parameters can be passed in from the pipeline by property name.

If you pipe an object with properties that match both sets, parameters are bound using __AllParameterSets, the AmbiguousParameterSet error is processed, but the end/endprocessing block still executes.

If you specify parameters manually, the command completely fails, without executing the end/endprocessing blocks.

This happens in both PowerShell v2 as well as PowerShell v3.
Details
Sign in to post a comment.
Posted by Tom Nolan [MSFT] on 6/4/2013 at 6:50 PM
Also, the code you tested in your example is different than my reproduction. When I use your code I get the following, which includes output from the end block of the function.

You should not have to change the error action preference to stop in this example to prevent output since the first and second examples are terminating errors.

This seems like a clear regression based on the different behaviors in parameter binding here.



New-Object psobject -property @{"A"="test1";"B"="test2"} | foo
Foo : Parameter set cannot be resolved using the specified named parameters.
At line:1 char:60
+ New-Object psobject -property @{"A"="test1";"B"="test2"} | foo
+                                                            ~~~
    + CategoryInfo         : InvalidArgument: (@{A=test1; B=test2}:PSObject) [Foo], ParameterBindingException
    + FullyQualifiedErrorId : AmbiguousParameterSet,Foo

DEBUG: __AllParameterSets
DEBUG:
Key                                                     Value                                                
---                                                     -----                                                
A                                                     test1                                                
B                                                     test2                                                
Posted by Tom Nolan [MSFT] on 6/4/2013 at 6:44 PM
Not sure I follow the message posted here... if you run the code from the details it fails like you mentioned, as I said it would in the code.

The issue here is that in the third and fourth examples, the end block is still being executed, whereas in the first and second, it is not.



Here is the output from the sample code so you don't need to run it.


DEBUG: Foo: Expecting this to fail, it does fail.
Foo : Parameter set cannot be resolved using the specified named parameters.
At line:53 char:48
+ New-Object psobject -Property @{"C"="test1"} | foo -a test1 -b test2
+                                                ~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo         : InvalidArgument: (:) [Foo], ParameterBindingException
    + FullyQualifiedErrorId : AmbiguousParameterSet,Foo

DEBUG: Get-Foo: Expecting this to fail, it does fail.
Get-Foo : Parameter set cannot be resolved using the specified named parameters.
At line:56 char:48
+ New-Object psobject -Property @{"C"="test1"} | Get-Foo -a test1 -b test2
+                                                ~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo         : InvalidArgument: (:) [Get-Foo], ParameterBindingException
    + FullyQualifiedErrorId : AmbiguousParameterSet,TinyInt.ScratchModule.GetFoo

DEBUG: Foo: Expecting this to fail, it errors, but it still executes.
Foo : Parameter set cannot be resolved using the specified named parameters.
At line:59 char:72
+ New-Object psobject -property @{"A"="test1";"B"="test2";"C"="test3"} | foo
+                                                                        ~~~
    + CategoryInfo         : InvalidArgument: (@{C=test3; B=test2; A=test1}:PSObject) [Foo], ParameterBinding
Exception
    + FullyQualifiedErrorId : AmbiguousParameterSet,Foo

DEBUG: __AllParameterSets
DEBUG:
Key                                                     Value                                                
---                                                     -----                                                
A                                                     test1                                                
B                                                     test2                                                
C                                                     test3                                                



DEBUG: Get-Foo: Expecting this to fail, it errors, but it still executes.
Get-Foo : Parameter set cannot be resolved using the specified named parameters.
At line:62 char:72
+ New-Object psobject -property @{"A"="test1";"B"="test2";"C"="test3"} | Get-Foo
+                                                                        ~~~~~~~
    + CategoryInfo         : InvalidArgument: (@{C=test3; B=test2; A=test1}:PSObject) [Get-Foo], ParameterBin
dingException
    + FullyQualifiedErrorId : AmbiguousParameterSet,TinyInt.ScratchModule.GetFoo

DEBUG: __AllParameterSets
DEBUG: A: test1
DEBUG: B: test2
DEBUG: C: test3
Posted by Microsoft on 6/4/2013 at 4:14 PM
In PowerShell V2,V3, and V4 -> New-Object psobject -property @{"A"="test1";"B"="test2"} | foo
threw the following message:

foo : Parameter set cannot be resolved using the specified named parameters.
At line:1 char:63
+ New-Object psobject -property @{"A"="test1";"B"="test2"} | foo <<<<
    + CategoryInfo         : InvalidArgument: (@{A=test1; B=test2}:PSObject) [foo], ParameterBindingException
    + FullyQualifiedErrorId : AmbiguousParameterSet,foo
Posted by Microsoft on 6/4/2013 at 4:13 PM
In PowerShell V2,V3, and V4 -> New-Object psobject -property @{"A"="test1";"B"="test2"} | foo
threw the following message:

foo : Parameter set cannot be resolved using the specified named parameters.
At line:1 char:63
+ New-Object psobject -property @{"A"="test1";"B"="test2"} | foo <<<<
    + CategoryInfo         : InvalidArgument: (@{A=test1; B=test2}:PSObject) [foo], ParameterBindingException
    + FullyQualifiedErrorId : AmbiguousParameterSet,foo
Sign in to post a workaround.