Powershell 7: Script doesn't work when packaged in .exe (0x80131621)

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 2 years and 8 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.
agitelgroupe
Posts: 2
Last visit: Sat Apr 22, 2023 12:49 pm

Powershell 7: Script doesn't work when packaged in .exe (0x80131621)

Post by agitelgroupe »

Product, version and build:PowerShell Studio 2021 5.8.191.0
Operating system: Windows Server 2019
PowerShell version(s): 7.1.3


Hello,

I'm trying to make a .exe with PowerShell Studio 2021 and Powershell 7, it's a Windows Form.
I'm able to build it, but when I try to start the .exe file on my dev computer or on my own computer it always return this error:
Could not load file or assembly 'System.Management.Automation, Version=7.1.3.0, Culture = neutral, PublicKeyToken=31bf3856ad364e35'.
Could not find or load a specific file. (0x80131621)
I was starting to think there was an issue in my script, so I created a new Windows Form, Dialog style, builded it right away and got the same result.
The form is able to be executed inside Sapien but fail when packaged in .exe.
I've tried to install the PowerShell 7 Runtimes from Sapien, the .NET 5, .NET Core 3.1 and .NET Desktop 3.1 I found at microsoft but it still doesn't work.
Am i missing something or is it just not compatible ATM?

Best Regards,
Mathis.
User avatar
brittneyr
Site Admin
Posts: 1655
Last visit: Thu Mar 28, 2024 9:46 am
Answers: 39
Been upvoted: 30 times

Re: Powershell 7: Script doesn't work when packaged in .exe (0x80131621)

Post by brittneyr »

With .NET and PowerShell 7, a packaged application is not a single file. The folder containing the application file is considered the actual application. This means all the additional files in that folder are required for the packaged script to run.
It also means when deploying this to other machines, the specific version of PowerShell and .NET are needed on that machine for your packaged executable to run. We do provide runtimes that will allow applications to run on machines without that specific PowerShell 7 version installed:
SPS_RibbonPowerShellRuntimes.png
SPS_RibbonPowerShellRuntimes.png (40.23 KiB) Viewed 7638 times
For more information about this, I recommend reading the following article:
https://www.sapien.com/blog/2020/08/12/ ... -net-core/



Are you able to run you build and run your exe through PowerShell Studio or SAPIEN Script Packager:
SPS_RibbonBuildAndRun.png
SPS_RibbonBuildAndRun.png (42.21 KiB) Viewed 7638 times
Packager_RunPackager.png
Packager_RunPackager.png (25.65 KiB) Viewed 7638 times
Brittney
SAPIEN Technologies, Inc.
agitelgroupe
Posts: 2
Last visit: Sat Apr 22, 2023 12:49 pm

Re: Powershell 7: Script doesn't work when packaged in .exe (0x80131621)

Post by agitelgroupe »

Hello Brittney,

Thank you for your answer. Your link is really interesting!
I've tried to Build & Run and it's working, so i've tried to start my packaged app directly and it's working too.
Is it possible that the issue was present because I was starting the app from my remote drive ? I did some modification on my ExecutionPolicy yesterday as a workaround for another issue with another script, but I did not tried again to start this package until now.

Also, does Powershell 7 Windows Service is planned to be available in the future, and which OS is supported by the runtimes?

Best Regards,
Mathis.
User avatar
brittneyr
Site Admin
Posts: 1655
Last visit: Thu Mar 28, 2024 9:46 am
Answers: 39
Been upvoted: 30 times

Re: Powershell 7: Script doesn't work when packaged in .exe (0x80131621)

Post by brittneyr »

The computer that is running the executable is where the .NET version and PowerShell version (whether it is the full PowerShell install or our runtimes). In the past, .NET applications did not run from an untrusted source like a network drive. This could be the problem.
You may find the following links helpful:
https://social.msdn.microsoft.com/Forum ... m=netfxbcl
https://docs.microsoft.com/en-us/dotnet ... full-trust

At this point in time, there are no plans in motion for a SAPIEN PowerShell 7 Windows Service engine for packaging.
The runtimes support the same operating systems that our products support:
Windows Server 2016 / 2019 or Windows 10, 64-bit versions supported
Brittney
SAPIEN Technologies, Inc.
This topic is 2 years and 8 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.