Linqpad script connects to API in GUI but not with LPRun
Hello.
Been searching for help with this issue, but not finding anything here or in stackoverflow, so posting the question here.
I have a linq script (C# program) that calls an API. When I run the script using the Linqpad GUI, the script succeeds, the API is called and a response is returned. When I run the script using LPRun, the API request is sent, but there is an error message returned every time -- "The underlying connection was closed: An unexpected error occurred on a send."
The script has a reference to RestClient that it uses to connect to the API.
Any thoughts on why the API call does not work when called by LPRun?
Thank you!
Comments
What version of LPRun are you using? (LPRun will report the version if run without arguments.)
Version=5.22.02(AnyCPU)
I thought the issue might be that RestSharp is a nuget. I changed it to a reference to a .dll on the server, and that didn't resolve the issue. I also copied the nuget files that were in my local user appdata folder to the appdata folder for LinqpadTaskUser, that didn't resolve it either.
Hi. Found the solution, suggested on the RestSharp website. .NET needed a line of code to accept additional cert types. Below is from https://restsharp.dev/get-help/faq.html#connection-closed-with-ssl :
When connecting via HTTPS, you get an exception:
The underlying connection was closed: An unexpected error occurred on a send
The exception is thrown by WebRequest so you need to tell the .NET Framework to accept more certificate types than it does by default.
Adding this line somewhere in your application, where it gets called once, should solve the issue:
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;