Creating GUI - Null Valued Expression?

I am attempting to make a GUI that our Help Desk can utilize when deploying newly imaged machines. I apologize if this is a stupid question but I’m stumped.

I am using ISE Steroids/Visual Studio to create it and am fairly confident I know what the issue is but I’m not entirely sure how to resolve the problem.

When I run it on my computer it works fine but when I go to run the script or converted EXE on another machine I receive an error…

You cannot call a method on a null-valued expression.
At C:\Users\bb16480\Desktop\UItest.ps1:73 char:1
+ $SEP.add_Click(
+ ~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

I couldn’t get the code to load the $XAML in here so I put it in pastebin at: function Convert-XAMLtoWindow{ param ( [Parameter(Mandatory=$ - Pastebin.com

Well, it’s thinking that $SEP doesn’t actually contain anything. I’m not seeing that in your code, though. It seems as if you expect $SEP to be a form object…?

BTW, you can also use Gists here. If you paste the Gist URL into the forums, it’ll retrieve and display your code all pretty-like.

Sorry, I believe I was testing something else but that didn’t work and I put in the incorrect error. :frowning:

It’s not $Sep it’s $Windows.SEP

You cannot call a method on a null-valued expression.
At C:\Users\bb16480\Desktop\UItest.ps1:73 char:22
+ $window.SEP.add_Click <<<< (
    + CategoryInfo          : InvalidOperation: (add_Click:String) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

This does run on my Win10 machine with ISE-Steroids but when I try to run this script on our normal Win7 client machines, this is when the error comes up. The GUI does popup but I still receive the error code.

Hopefully that makes sense. I’m trying hard to wrap my head around all this. Also thanks for the tremendous sessions @MMS this year, it was fantastic.

I don’t see the rest of the code that creates the form at that link.

Hopefully this helps for viewing?

https://gist.github.com/bbalz/8d2761945455b5ccf0b86bcd0405c75a

The form works for me on win7.

$window.SEP.add_Click(
{
[System.Object]$sender = $args[0]
[System.Windows.RoutedEventArgs]$e = $args[1]

write-host ‘sep clicked’

}
)

Oy… well it turns out it was something with the VM I was testing this on that caused an issue.

Appreciate you checking it out and sorry about that. I was kind of banging my head on the wall the past hour or so in between some other work and it turns out it was fine after all.

Uffta…

Did you have any luck with figuring this out?
I am seeing the same issue on a vista machine. I believe its due to something not being up to date, but Im not sure what.