Please feel free to provide feedback or file bugs here.

PS 5 assigning to list value while PS 4 isn´t

Hi!

We recently got WMF 5.1 (KB3191566) that included PS 5.
We then began finding differences in the behavior of PS 5 and PS 4 when running our scripts. The result was different.

We didn´t notice this problem since someone wrapped it in a try catch block... So to recreate this issue/bug I made this script and ran it on one host with PS 5 and one VM host on PS 4.

add-type -Language CSharpVersion3 -TypeDefinition @"
public class TestClass
{
public System.Collections.Generic.List<System.Int32> listObject { get; set; }
}
"@

[string]$string = "1"

$classWithList = New-Object TestClass

$classWithList.listObject = $string

The result was indeed different. PS 4 would throw an exception (Exception setting "listObject": "Cannot convert the "1" value of type "System.String" to type "System.Collections.Generic.List`1[System.Int32]".") and PS 5 would add the string as an int.

I know the script is really badly written, but this makes the script not backward compatible.

Is this a known problem?

Do I have to re-write the script or is there a way to make it backward compatible with PS 4?

Thanks!

Best regards,
Lucas Ohlson

1 vote
Sign in
Check!
(thinking…)
Reset
or sign in with
  • facebook
  • google
    Password icon
    I agree to the terms of service
    Signed in as (Sign out)

    We’ll send you updates on this idea

    Lucas Ohlson shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

    1 comment

    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      I agree to the terms of service
      Signed in as (Sign out)
      Submitting...

      Feedback and Knowledge Base