TLS1.2 request fails from Hangfire task

Tags: #<Tag:0x00007fafecfe17f0>

I’ve got a bit of a conundrum. I’ve created a piece of code to download data from an external API, parse and process it. In my console app this works correctly. When started from Hangfire it fails.

The specific error I’m dealing with is identical to the issue described in this StackOverflow question. In fact, I’ve had the same issue when I was initially developing my code, and in my console app the suggested solution (to set up the ServicePointManager.SecurityProtocol value) allowed me to continue. However, the same solution in Hangfire seems to do nothing, and I keep getting the same error as before.

Given that Hangfire tasks are ran differently than a normal C# console app, I’m thinking there might be more to this than meets the eye. Has anyone had any issues connecting to TLS1.2 secured sites / APIs from a Hangfire task?

Found the reason - it turned out to be related to the server itself that was hosting Hangfire, rather than the code.