Event Handlers Invalid cast

Feb 4, 2012 at 2:06 AM

 Hello

I have recently installed powershell 3.0 and ShowUI (great tool thank you) on my system, however I am experiencing some unexpected behavior.

Any event handler I use generates an invalid cast error. Example Code: (Sorry for some reason the insert code option is not responding for me - using chrome)

 

stackpanel -ControlName sp1 -Children{   

button -Content "Click" -name button1 -On_Click{$rLabel.Content = get-random} -On_MouseEnter{

$rLabel.Background = "Black"

$rLabel.Foreground = "White"   

}   

label -name rLabel

} -show

 

Errors:

Specified cast is not valid.

Error in On_MouseEnter Event Handler on button1 (Button)

 At line:3 char:1+ $ErrorActionPreference = 'stop'

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Specified cast is not valid.Error in On_Click Event Handler on button1 (Button)

At line:3 char:1+ $ErrorActionPreference = 'stop'

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Coordinator
Feb 4, 2012 at 5:28 PM

What version of ShowUI are you using? (You can check with Get-Module | fl )

Feb 5, 2012 at 1:19 AM

It is version 1.3. 

When I first had this problem, I removed the module and re-downloaded the latest release from codeplex.

Is there a specific file within the module I could check for this?

Apr 24, 2012 at 9:28 PM

I have this problem too, it doesnt work correctly in powershell 3.0, which is a real shame as 2.0 ISE crashes a lot for me with ShowUI.

Anyone found a fixed for this yet?

Coordinator
Apr 25, 2012 at 4:52 AM

That exact code is working for me in a post-beta release of PowerShell 3 with ShowUI 1.3, so I'm going to go with: just wait a minute, it will change...

Apr 25, 2012 at 9:49 AM
Edited Apr 25, 2012 at 9:51 AM

Yes the code works fine, but every time you click the button it outputs an error in the console. You don't see any errors at all?

I dont know where it gets this from:

At line:3 char:1
+ $ErrorActionPreference = 'stop'

Even if you try to override this with SilentlyContinue it doesn't work.

Are there any plans to update ShowUI for PS 3.0?

Anyone know when PS 3.0 is going to be released out of beta?

Coordinator
Apr 26, 2012 at 12:58 AM

The ErrorActionPreference is ShowUI magic, because otherwise you wouldn't get any notice that you had an error in the event handler ... we add an error handler, and set it to stop so we can trap errors.

The script works as is on my build (you'll just have to wait for the next public CTP of PowerShell 3)