Importing Modules works in .exe and not while debugging

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 SUBSCRIPTION NUMBERS, LICENSE 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.
User avatar
ffulde
Posts: 5
Joined: Wed Feb 07, 2018 11:33 pm

Importing Modules works in .exe and not while debugging

Post by ffulde » Thu Apr 11, 2019 3:51 am

Product, version and build:
Product: PowerShell Studio 2019 (64 Bit)
Build: v5.6.161
OS: Windows 10 Pro (64 Bit)
Build: v10.0.17134.0

32 or 64 bit version of product: 64 Bit
Operating system: Windows 10 Pro
32 or 64 bit OS: 64 bit

I am seeing some strange behaviour with my Installation since yesterday. At the start of the application I load some modules namely ActiveDirectory and Exchange from their respective servers.

Code: Select all

	$global:AdminCredential = Get-Credential
	
	$dc = "DC"
	$session = New-PSSession -ComputerName $dc -Credential $global:AdminCredential
	Import-Module -PSSession $session -Name ActiveDirectory
	
	#EXCH Modul laden
	$exch = "EXCH"
	$s = New-PSSession -ConnectionUri "http://$exch/Powershell" -ConfigurationName Microsoft.Exchange -Credential $global:AdminCredential
	import-pssession $s
	
When building the project and running it as an .exe file everything works fine however if I debug it in PS Studio I get error messages.
Fresh Installation of PS Studio did not do anything either.

Code: Select all

ERROR: Import-Module : Fehler im Remotebefehl: Import-Module -Name 'ActiveDirectory': Ein Aufrufziel hat einen Ausnahmefehler verursacht.
ERROR: In C:\Users\xxxx\Documents\SAPIEN\PowerShell Studio\Projects\xxxx\xxxx.Run.ps1:60 Zeichen:2
ERROR: +     Import-Module -PSSession $session -Name ActiveDirectory
ERROR: +     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ERROR:     + CategoryInfo          : NotSpecified: (:) [Import-Module], InvalidOperationException
ERROR:     + FullyQualifiedErrorId : PSRemotingTransportException,Microsoft.PowerShell.Commands.ImportModuleCommand
ERROR:
ERROR: import-pssession : Nicht genügend Arbeitsspeicher.
ERROR: In C:\Users\xxx\Documents\SAPIEN\PowerShell Studio\Projects\xxxx\xxxx.Run.ps1:65 Zeichen:2
ERROR: +     import-pssession $s
ERROR: +     ~~~~~~~~~~~~~~~~~~~
ERROR:     + CategoryInfo          : NotSpecified: (:) [Import-PSSession], OutOfMemoryException
ERROR:     + FullyQualifiedErrorId : System.OutOfMemoryException,Microsoft.PowerShell.Commands.ImportPSSessionCommand
Some of this is in German I hope you can make sense of it anyways if not I will try to translate that.

Running those commands in a local PowerShell works fine. Just the debugging doesn't work.

User avatar
davidc
Posts: 5913
Joined: Thu Aug 18, 2011 4:56 am

Re: Importing Modules works in .exe and not while debugging

Post by davidc » Thu Apr 11, 2019 7:31 am

If you Run the script using [Ctrl + F5] instead of Debugging [F5], do you still get an error? This will help us determine if it is an issue with our internal host as a whole or just while debugging.

The second exception is an out of memory error.

1. Do you have any firewall restrictions?
2. And are you using the same settings as the Packaged Executable? i.e. Platform 64/32, PowerShell Version, Elevation, etc.
David
SAPIEN Technologies, Inc.

User avatar
ffulde
Posts: 5
Joined: Wed Feb 07, 2018 11:33 pm

Re: Importing Modules works in .exe and not while debugging

Post by ffulde » Thu Apr 11, 2019 10:26 pm

Ctrl + F5 still throws those Errors

No Firewall Restrictions active and PSRemoting works to both Systems (tested with enter-pssession)
Using "Elevated" + "STA Mode" on "V5 - 64 Bit" while debugging.

Deploy settings are "V5 Host (Windows Forms)" on "Microsoft Windows 64 Bit".

User avatar
ffulde
Posts: 5
Joined: Wed Feb 07, 2018 11:33 pm

Re: Importing Modules works in .exe and not while debugging

Post by ffulde » Fri Apr 12, 2019 2:18 am

Also additional Things I have tried so far:
- Creating a new Project and just loading the modules - errors persist
- Moving the module loading out of the Main() function into the form - (worked once ? afterwards errors again)
- Compiling as 32Bit v5 - errors persist

Also even tho I set the $global:ProgressPreference to not show it (this worked in the past aswell) I get a window telling me its loading the AD Module (Also just in the Debugger/Run option not as a packaged .exe)

Maybe some of this helps :)

User avatar
davidc
Posts: 5913
Joined: Thu Aug 18, 2011 4:56 am

Re: Importing Modules works in .exe and not while debugging

Post by davidc » Fri Apr 12, 2019 7:17 am

I believe it could be that the internal host doesn't support PSSessions. I will ask the dev team to look into it. It is interesting that it works in the packager engine since the hosts are very similar.
David
SAPIEN Technologies, Inc.

User avatar
davidc
Posts: 5913
Joined: Thu Aug 18, 2011 4:56 am

Re: Importing Modules works in .exe and not while debugging

Post by davidc » Fri Apr 12, 2019 8:27 am

So, it only works in a x64 V5 package executable?
David
SAPIEN Technologies, Inc.

User avatar
ffulde
Posts: 5
Joined: Wed Feb 07, 2018 11:33 pm

Re: Importing Modules works in .exe and not while debugging

Post by ffulde » Mon Apr 15, 2019 4:26 am

Havn't tested that yet - but it certainly works in 64bit V5 executable. Can't test atm as I have the week off.

Funny thing is it worked in debugging just a couple days ago which is why I find it odd to just not work all of a sudden.

User avatar
ffulde
Posts: 5
Joined: Wed Feb 07, 2018 11:33 pm

Re: Importing Modules works in .exe and not while debugging

Post by ffulde » Mon Apr 22, 2019 11:28 pm

I have narrowed this down to being a Problem with the importing of the ActiveDirectory Module.
If i just run the Exchange part by itself it works fine and reliably.

Still bumping my head against the wall with this one tho.

Seems to be a duplicate to this Topic:
viewtopic.php?t=11827

User avatar
davidc
Posts: 5913
Joined: Thu Aug 18, 2011 4:56 am

Re: Importing Modules works in .exe and not while debugging

Post by davidc » Tue Apr 23, 2019 7:17 am

As a workaround, you could use the "Run in Console" [Ctrl + F8] command.

Could something be blocking the process connection for some odd reason. PowerShell Studio uses the ScriptDriverXX.exe executables to run the scripts. They are located in the following folders:

C:\Program Files\SAPIEN Technologies, Inc\PowerShell Studio 2019\Debugger32
C:\Program Files\SAPIEN Technologies, Inc\PowerShell Studio 2019\Debugger64
David
SAPIEN Technologies, Inc.