Please feel free to provide feedback or file bugs here.

Flags Enumeration Bitwise Operations Fail With 'Specified cast is not valid' Error

Votes from Connect: 3

Original Date Submitted: 2/19/2015 11:08:09 PM

Description:

********Contact Information********
Handle: Rohn Edwards
Site Name: PowerShell
Feedback ID: 1138469
***************************************

Frequency: Always Happens
Regression: No, this is new to the most recent version

Problem Description:
In the December 2014 and February 2015 WMF 5.0 previews, flags enumerations that have byte, sbyte, short, or ushort underlying types have to be cast or coerced to a numeric type before -band, -bor, or -bxor bitwise operations will work.

int, uint, long, and ulong underlying types still work as expected.

Product Studio item created by Connect Synchronizer due to creation of feedback ID 1138469 (http://connect.microsoft.com/PowerShell/feedback/ViewFeedback.aspx?FeedbackID=1138469).

Repro Steps:
First, ensure $PSVersionTable.PSVersion is 5.0.10018.0

To see the error, run this command:
PS> [System.Windows.Input.KeyStates]::Down -band [System.Windows.Input.KeyStates]::Down

KeyStates has an underlying type of 'Byte'. The command works if you modify it like this:
PS> [System.Windows.Input.KeyStates]::Down.value__ -band [System.Windows.Input.KeyStates]::Down

Expected Results:
No errors are expected, like running this command:
[System.Windows.Forms.ButtonState]::Pushed -band [System.Windows.Forms.ButtonState]::Pushed

It appears that version 5 returns an instance of the enumeration instead of a numeric value (which it looks like previous versions return).

Internal BugId: 13250

1 vote
Sign in
(thinking…)
Sign in with: Facebook Google
Signed in as (Sign out)

We’ll send you updates on this idea

AdminJoey Aiello [MSFT] (Program Manager, Windows Server) shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

0 comments

Sign in
(thinking…)
Sign in with: Facebook Google
Signed in as (Sign out)
Submitting...

Feedback and Knowledge Base