EXOV3 and ActiveDirectory modules Non-Thread STA issue in PS5.1 and PSS 2023

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 1 year and 1 month 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
Alexander Riedel
Posts: 8479
Last visit: Thu Mar 28, 2024 9:29 am
Answers: 19
Been upvoted: 37 times

Re: EXOV3 and ActiveDirectory modules Non-Thread STA issue in PS5.1 and PSS 2023

Post by Alexander Riedel »

If you feel adventurous, replace the PowerShellDebuggerV5.dll here:
C:\Program Files\SAPIEN Technologies, Inc\PowerShell Studio 2023\Debugger64
with the one in the attached zip file for a test. No promises. And make sure you backup the original so you can restore that.
Let me know if that makes any difference whatsoever.
Attachments
PowerShellDebuggerV5.zip
(30.79 KiB) Downloaded 84 times
Alexander Riedel
SAPIEN Technologies, Inc.
DarusDP
Posts: 43
Last visit: Fri Feb 09, 2024 1:02 pm
Been upvoted: 1 time

Re: EXOV3 and ActiveDirectory modules Non-Thread STA issue in PS5.1 and PSS 2023

Post by DarusDP »

The other debugger you provided made no difference.

If I make a simple script (below) where I connect to EXOV3 first and then import-module ActiveDirectory then all is well.

Code: Select all

Import-Module ExchangeOnlineManagement
$null = Remove-Module -Name ActiveDirectory -ErrorAction SilentlyContinue
Connect-ExchangeOnline -UserPrincipalName "<user>@<email.domain>" -ShowBanner:$false
However, in my real application, even if I put the simple code (above) in my application in the Startup.pss (Build Order 0) near the very top (further below) then I get the ActiveX error.

Maybe that will lead to another avenue of ideas to try.

Code: Select all

#Requires -Version 5.0

#Define a Param block to use custom parameters in the project
#Param ($CustomParameter)
Param (
	[Parameter(Mandatory = $False)]
	$Tier = 'PR'
	,
	[Parameter(Mandatory = $False)]
	$CheckAD = 'true'
	,
	[Parameter(Mandatory = $False)]
	$LocalConfig = 'false'
	,
	[Parameter(Mandatory = $False)]
	$SubmitRequest = 'true'
	,
	[Parameter(Mandatory = $False)]
	$UseReqVer = 'false'
)

Import-Module ExchangeOnlineManagement
$null = Remove-Module -Name ActiveDirectory -ErrorAction SilentlyContinue
Connect-ExchangeOnline -UserPrincipalName "<user>@<email.domain>" -ShowBanner:$false
User avatar
Alexander Riedel
Posts: 8479
Last visit: Thu Mar 28, 2024 9:29 am
Answers: 19
Been upvoted: 37 times

Re: EXOV3 and ActiveDirectory modules Non-Thread STA issue in PS5.1 and PSS 2023

Post by Alexander Riedel »

There must be something else at play here, because any combination I try here works just fine.
I would venture a guess that you might need to remove the AD module BEFORE you import the Exchange module, but in a script that runs in PowerShell Studio, the remove is not necessary.

PowerShell Studio ALWAYS creates a new process and a new runspace, so there is no AD module loaded unload you specifically load it.
Have you by any chance run this on another computer or outside an AD environment? I just wonder what other interactions there might be.
Alexander Riedel
SAPIEN Technologies, Inc.
DarusDP
Posts: 43
Last visit: Fri Feb 09, 2024 1:02 pm
Been upvoted: 1 time

Re: EXOV3 and ActiveDirectory modules Non-Thread STA issue in PS5.1 and PSS 2023

Post by DarusDP »

I have not run on another computer, nor outside of AD environment.

I made a new project and added files one by one and tested and at this point I think this line is the culprit

#Requires -Modules ActiveDirectory

but I need to do further testing, stay tuned.
DarusDP
Posts: 43
Last visit: Fri Feb 09, 2024 1:02 pm
Been upvoted: 1 time

Re: EXOV3 and ActiveDirectory modules Non-Thread STA issue in PS5.1 and PSS 2023

Post by DarusDP »

More to the story. Once I place the code to connect to EXOV3 is a form (MainForm.psf), even if it is the first code execute then I get the ActiveX error.

If I put the connect to EXOV3 code as the last thing I execute before MainForm.psf is called then all is well - kind of.

So, all is well in the new project I made to test and am adding one file of the project at a time. I don't yet have all the files added - so more testing to do.

However, if I do the same as what works in test project in my real project then I get the ActiveX error no matter what I do.

So it seems to me that there maybe something wrong with my real project settings.

To recap what seems to be needed (other than a project setting may be messed up) so far:
1. Remove any #Requires -Modules ActiveDirectory
2. Make connection to EXOV3 before any form call or import-module ActiveDirectory
It is ok to disconnect EXOV3 before any form called and then do a connect within your form if needed.

Any ideas about how to diagnose project settings that may be causing as issue?
User avatar
brittneyr
Site Admin
Posts: 1655
Last visit: Thu Mar 28, 2024 9:46 am
Answers: 39
Been upvoted: 30 times

Re: EXOV3 and ActiveDirectory modules Non-Thread STA issue in PS5.1 and PSS 2023

Post by brittneyr »

To help see how your project settings are configuring your project's script, try exporting your project (Deploy->Export) and looking at the order of code in the exported PS1 file.
Brittney
SAPIEN Technologies, Inc.
DarusDP
Posts: 43
Last visit: Fri Feb 09, 2024 1:02 pm
Been upvoted: 1 time

Re: EXOV3 and ActiveDirectory modules Non-Thread STA issue in PS5.1 and PSS 2023

Post by DarusDP »

I think I now have a consistent workaround.
1. The removing of #Requires -Modules ActiveDirectory is not necessary
2. In Startup.pss in the Main function before showing any form do this code. Even if this fails, its ok.

Code: Select all

$exoModVer = Get-Module -Name ExchangeOnlineManagement | Select-Object Version
if ($exoModVer.Version.Major -ge 3)
{
	try
	{
		$null = Remove-Module -Name ActiveDirectory -ErrorAction SilentlyContinue
		$Error.clear()
		Connect-ExchangeOnline -UserPrincipalName "user@email.domain" -ShowBanner:$false
		$a = Get-ConnectionInformation
		Disconnect-ExchangeOnline -Confirm:$false
	}
	catch
	{ }
}
3. In a form the same code as in #2 is ran where I need it to and then I import-module ActiveDirectory

All is fine.
It is still baffling as to why.

For now I think the issue has a workable workaround.
User avatar
Alexander Riedel
Posts: 8479
Last visit: Thu Mar 28, 2024 9:29 am
Answers: 19
Been upvoted: 37 times

Re: EXOV3 and ActiveDirectory modules Non-Thread STA issue in PS5.1 and PSS 2023

Post by Alexander Riedel »

Most likely it is the same cause as for some other .NET framework and Windows Forms problems. There was a recent update that broke some things.
It is not too far fetched that it also affected Windows PowerShell in some areas, since that is based on .NET framework.
We are still investigating exactly what happened.
Alexander Riedel
SAPIEN Technologies, Inc.
This topic is 1 year and 1 month 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.