Script kills PowerShell Universal when ran in API

Product: PowerShell Universal
Version: 1.4.6

So it appears that when I run my function and open a connection to oracle using

New-Object Oracle.ManagedDataAccess.Client.OracleConnection($connectionstring)
$con.Open()

It causes PowershellUniversal service to crash with this error.

Application: Universal.Server.exe
CoreCLR Version: 5.0.921.35908
.NET Version: 5.0.9
Description: The process was terminated due to an unhandled exception.
Exception Info: System.TypeLoadException: Could not load type 'System.Security.Principal.WindowsImpersonationContext' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
   at OracleInternal.ConnectionPool.PoolManager`3.CreateNewPRThreadFunc(Object state)
   at System.Threading.QueueUserWorkItemCallback.<>c.<.cctor>b__6_0(QueueUserWorkItemCallback quwi)
   at System.Threading.ExecutionContext.RunForThreadPoolUnsafe[TState](ExecutionContext executionContext, Action`1 callback, TState& state)
   at System.Threading.QueueUserWorkItemCallback.Execute()
   at System.Threading.ThreadPoolWorkQueue.Dispatch()

and then

Faulting application name: Universal.Server.exe, version: 1.0.0.0, time stamp: 0x60e896d9
Faulting module name: KERNELBASE.dll, version: 10.0.19041.1202, time stamp: 0xc9db1934
Exception code: 0xe0434352
Fault offset: 0x0000000000034f99
Faulting process id: 0x681c
Faulting application start time: 0x01d7d1da44222e19
Faulting application path: C:\ProgramData\PowerShellUniversal\Server\Universal.Server.exe
Faulting module path: C:\WINDOWS\System32\KERNELBASE.dll
Report Id: 97a15ca9-767f-4fa7-9bbd-42ed34442c66
Faulting package full name: 
Faulting package-relative application ID: 

If I run this as a script it has no issues and returns the results. Any idea why it doesn’t work?

Any help is appreciated.

So it appears you have to use the .net core Oracle.ManagedDataAccess.dll and you have to use Powershell 7. Does the API specify using PowerShell 7?

You can change the API environment by setting it in Settings \ General \ Environments. Try selecting PS7 from there and see if you have more luck.

I’m going to open an issue for this because APIs should never kill the PSU process.