Buttons stop working after build

This forum can be browsed by the general public. Posting is limited to current SAPIEN license holders with active maintenance and does not offer a response time guarantee.
Forum rules
DO NOT POST LICENSE NUMBERS, ACTIVATION KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 6 years and 7 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
User avatar
lucassawyer
Posts: 5
Last visit: Wed Aug 16, 2017 3:53 pm

Buttons stop working after build

Post by lucassawyer »

PowerShell Studio 2016, version 5.2.120, x64
Server 2012 R2

My button actions (on click) stop working after I create a build (exe)

However, if I export to file and run the script the buttons work just fine.

I've tried recreating the buttons, no change.

Any suggestions?
User avatar
Alexander Riedel
Posts: 8488
Last visit: Tue Apr 16, 2024 8:42 am
Answers: 20
Been upvoted: 37 times

Re: Buttons stop working after build

Post by Alexander Riedel »

The critical pieces of information here would be:
1. What do the buttons do?
2. What error messages do you get, if any?
3. What packaging options do you use to build an executable?
4. All buttons don't work or just some?
Alexander Riedel
SAPIEN Technologies, Inc.
User avatar
lucassawyer
Posts: 5
Last visit: Wed Aug 16, 2017 3:53 pm

Re: Buttons stop working after build

Post by lucassawyer »

Two that don't work:
One button clears form fields
Another button exports a file and opens another window

One that does work:
An image when clicked opens Chrome

No error messages.

I've only tried checking and unchecking STA.
User avatar
Alexander Riedel
Posts: 8488
Last visit: Tue Apr 16, 2024 8:42 am
Answers: 20
Been upvoted: 37 times

Re: Buttons stop working after build

Post by Alexander Riedel »

In that case you will need to post some code. There is nothing obvious sticking out.
Generally problems like this involve scope problems, uninitialized variables or access denied issues (for files).
Maybe you can make a sample project with just the clear form fields handler and post that here.
Alexander Riedel
SAPIEN Technologies, Inc.
User avatar
lucassawyer
Posts: 5
Last visit: Wed Aug 16, 2017 3:53 pm

Re: Buttons stop working after build

Post by lucassawyer »

I wasn't getting any errors. After moving the project to another system, I now get this error:

ERROR: Unable to find type [System.Windows.MessageBox]

However, the command in my script (see below) works from the same system when run in PowerShell ISE.

[System.Windows.MessageBox]::Show("Are you sure you want to clear the request?",'Clear Request','YesNo','Question')

We are right in the middle of having PowerShell upgraded on all workstations, perhaps this is a versioning issue.
User avatar
lucassawyer
Posts: 5
Last visit: Wed Aug 16, 2017 3:53 pm

Re: Buttons stop working after build

Post by lucassawyer »

Very bizarre. Some elements were created with "[System.Windows.MessageBox]", others "[System.Windows.Forms.MessageBox]"

I changed the buttons to the latter, and it all works now.
User avatar
Alexander Riedel
Posts: 8488
Last visit: Tue Apr 16, 2024 8:42 am
Answers: 20
Been upvoted: 37 times

Re: Buttons stop working after build

Post by Alexander Riedel »

Yeah, you have a .NET framework versioning issue. I am not sure about the exact versions at the moment,
but I think System.Windows.MessageBox exists since .NET framework 3.0 and System.Windows.Forms.MessageBox was present since 1.1

The Powershell version you are using to package and run your executable translates also to a specific .NET runtime.
See https://www.sapien.com/blog/2015/11/16/ ... equisites/
Alexander Riedel
SAPIEN Technologies, Inc.
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: Buttons stop working after build

Post by davidc »

Also make sure you load the WinForms assembly beforehand. Not all hosts will pre-load the assembly.

Code: Select all

Add-Type -AssemblyName 'System.Windows.Forms'
David
SAPIEN Technologies, Inc.
This topic is 6 years and 7 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.