Page 1 of 1

Importing Modules works in .exe and not while debugging

Posted: Thu Apr 11, 2019 3:51 am
by ffulde
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.

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

Posted: Thu Apr 11, 2019 7:31 am
by davidc
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.

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

Posted: Thu Apr 11, 2019 10:26 pm
by ffulde
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".

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

Posted: Fri Apr 12, 2019 2:18 am
by ffulde
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 :)

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

Posted: Fri Apr 12, 2019 7:17 am
by davidc
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.

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

Posted: Fri Apr 12, 2019 8:27 am
by davidc
So, it only works in a x64 V5 package executable?

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

Posted: Mon Apr 15, 2019 4:26 am
by ffulde
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.

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

Posted: Mon Apr 22, 2019 11:28 pm
by ffulde
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

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

Posted: Tue Apr 23, 2019 7:17 am
by davidc
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