christophwille / pscore-playground

Programmatically drive PS Core with C# (mostly Exchange Online Powershell 3 and later)
MIT License
2 stars 1 forks source link

PowerShell RunspacePool Open Fails for Exchange Online PS 3.0(.1) - was working for 2.0.6 #4

Closed christophwille closed 1 year ago

christophwille commented 1 year ago

https://github.com/christophwille/pscore-playground/blob/858a06d070cb8387ccc7587c28283303eb435faa/ExO3onNet6LocalModule/ExO3PsLib/ExchangeOnlinePowerShellFactory.cs#L84-L105

This code works for 2.0.6, but fails for 3.0(.1) with the following exception:

System.Management.Automation.PSInvalidOperationException
  HResult=0x80131509
  Message=Running startup script threw an error: Cannot add type. Compilation errors occurred..
  Source=System.Management.Automation
  StackTrace:
   at System.Management.Automation.Runspaces.LocalRunspace.DoOpenHelper()
   at System.Management.Automation.Runspaces.RunspaceBase.CoreOpen(Boolean syncCall)
   at System.Management.Automation.Runspaces.Internal.RunspacePoolInternal.CreateRunspace()
   at System.Management.Automation.Runspaces.Internal.RunspacePoolInternal.OpenHelper()
   at System.Management.Automation.Runspaces.Internal.RunspacePoolInternal.CoreOpen(Boolean isAsync, AsyncCallback callback, Object asyncState)
   at System.Management.Automation.Runspaces.Internal.RunspacePoolInternal.Open()
   at ExO3PsLib.ExchangeOnlinePowerShellFactory.ConnectViaPool(String appId, String organization, X509Certificate2 certificate, String modulePath) in D:\GitWorkspace\pscore-playground\ExO3onNet6LocalModule\ExO3PsLib\ExchangeOnlinePowerShellFactory.cs:line 98

Inner Exception 1:
Exception: Cannot add type. Compilation errors occurred.