Consuming Module Classes in Forms Projects

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 4 years and 10 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
DavidSunter
Posts: 7
Last visit: Tue Aug 15, 2023 3:05 am

Consuming Module Classes in Forms Projects

Post by DavidSunter »

Product, version and build: PowerShell Studio 2019 5.6.162
32 or 64 bit version of product: 64 bit
Operating system: Windows 10 1709 16299.1087
32 or 64 bit OS: 64 bit

I have created a PowerShell module which contains classes. I have then created a new forms project and intend to use the classes exposed in the module by adding the statement 'using module ModuleName'. This works fine when running via PowerShell Studio, however, when I package the script in to an executable and run it, I get the following error:

Line 5: At line:4 char:1
+ Using module 'ModuleName'
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
A 'using' statement must appear before any other statements in a script.

I have tried placing the using statement in the Globals.ps1 file and also within the Startup.pss file without any success.
When exporting the script to the clipboard, I can see the first statement is the using one, so I guess the packager adds something else under the hood. Is it possible to get this working at all?
User avatar
Alexander Riedel
Posts: 8479
Last visit: Thu Mar 28, 2024 9:29 am
Answers: 19
Been upvoted: 37 times

Re: Consuming Module Classes in Forms Projects

Post by Alexander Riedel »

It is probably caused by the new injection of code which was requested to set the $ScriptRoot variable.
Please stand by.
Alexander Riedel
SAPIEN Technologies, Inc.
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: Consuming Module Classes in Forms Projects

Post by davidc »

If you can, please you zip and upload a sample project that demonstrates the issue here:

https://sapien.com/support/upload/

Thank you,
David
SAPIEN Technologies, Inc.
User avatar
Alexander Riedel
Posts: 8479
Last visit: Thu Mar 28, 2024 9:29 am
Answers: 19
Been upvoted: 37 times

Re: Consuming Module Classes in Forms Projects

Post by Alexander Riedel »

Make a backup of the current PSBuild.exe in your PowerShell Studio install folder.
Replace with the file attached here and see if that helps.
Attachments
PSBuild.zip
(184.95 KiB) Downloaded 88 times
Alexander Riedel
SAPIEN Technologies, Inc.
This topic is 4 years and 10 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.