While executing a Poweshell Workflow activity if you see following error
Exception: System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive. —> System.Management.Automation.PSInvalidOperationException: There is no Runspace available to run scripts in this thread. You can provide one in the DefaultRunspace property of the System.Management.Automation.Runspaces.Runspace type. The script block you attempted to invoke was: $true
that indicates that some powershell script has been executed which sets it to true. Typically you would see following command in the script
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
The key thing is, this becomes over-arching – that means, SerivcePointManager now implements this policy across all subsequent calls so even though this Powershell might have executing on some other process instance on a completely unrelated process, it will still affect further HttpRequest at network layer.
Please remove that line and restart server and monitor which will get rid of the issue. You can even try setting it to $null explicitly. Either removing or setting it to $null will help but restarting the server is a better idea once you fix the issue.
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = $null |
Error message clearly indicates that this powershell line is setting a value which causes issue in .Net runspace. The thing which most people get caught is when they don’t even see a PowerShell activity executed in the process throwing error as surprisingly when the command is run it takes over the whole server and not just executing thread.
Great blog. I have an old Posh module (PSFTP) that was setting this to $True and then PSPetes CredentialRetriever was crashing. Setting back to [System.Net.ServicePointManager]::ServerCertificateValidationCallback = $null fixed everything.
[Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
Try running this without the “system” context in front of NET.