Issues running in STA

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

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 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.
Locked
User avatar
akrofly
Posts: 30
Last visit: Fri Mar 24, 2023 3:33 am

Re: Issues running in STA

Post by akrofly »

My mistake, my attempt with the snapshot was to show you the STA setting configuration that I have chosen.
I have also chosen the correct "Windows Forms Hosts" and it does not work, it fails.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Issues running in STA

Post by jvierra »

Have you tried 32bit?
User avatar
akrofly
Posts: 30
Last visit: Fri Mar 24, 2023 3:33 am

Re: Issues running in STA

Post by akrofly »

Same error with the 32 bits as well.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Issues running in STA

Post by jvierra »

What is the error you are getting?
User avatar
akrofly
Posts: 30
Last visit: Fri Mar 24, 2023 3:33 am

Re: Issues running in STA

Post by akrofly »

2 error scenarios that I have experienced with the STA depending on how the script is formulated.
1) Transcription fails ( an output that gets manipulated later)
Start-Transcript : This host does not support transcription.
Used to retrieve the output of a T-query on the SQL 2008r2 servers, some sql queries do not work with out-file and since servers are running ps v2 "4>" is not working with verbose switch (works fine in PS1 running in STA not in EXE)

2) the 2 previously mentioned Snapins are not recognized. (again works fine during the running of the PS1 in STA not in EXE)
FullyQualifiedErrorId
Microsoft.PowerShell.Commands.AddPSSnapinCommand
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Issues running in STA

Post by jvierra »

What do you mean the snap-ins are not recognized? What tis the exact error?

The extra redirectors are not available in V2.

Start-Transcript is not available with the Windows Host V2. It I sonly available in the CLI version of PowerShell as it is part of the PS2 host and not a module or CmdLet.

My suspicion is that the snap-ins cannot be made to work in the Windows Forms Host for many other reasons due to how the old snap-in were designed. They were only supported in the PS2 CLI at first.

The native mode for the snap-ins is MTA. If you start sqlps you will see that it requires MTA.

Forms only require STA if you use certain dialogs such as the folder dialog.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Issues running in STA

Post by jvierra »

Have you tried loading the dll like this:

Import-Module 'C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\Microsoft.SqlServer.Management.PSSnapins.dll'
User avatar
akrofly
Posts: 30
Last visit: Fri Mar 24, 2023 3:33 am

Re: Issues running in STA

Post by akrofly »

Thank you for the information, I did not even think that transcription was not available in WHv2.

I am more leaning towards your suspicions regarding the snap-ins not working in Windows Forms Host.

I have not attempted to load the dll as you suggested, I will attempt that once I am back in the office later this evening and report to you then.

Regardless of the results, my extreme thanks for taking the time to respond.
User avatar
akrofly
Posts: 30
Last visit: Fri Mar 24, 2023 3:33 am

Re: Issues running in STA

Post by akrofly »

Importing the dll in the proposed manner worked.
But since transcription is not possible when compiled, we have to continue running it as a script in STA mode.
This topic is 6 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.
Locked