I have created a DLL [made available as a NuGet package (.NetStandard 2.0/2.1)].
When a particular class in this DLL is instantiated, we fire an synchronous GET call to a .Net Core WebAPI installed on IIS on my local machine (localhost) to load some configuration data.
This DLL makes use of a singleton HttpClient (we've following Microsoft's 'best practices' here)
I've consumed this NuGet package in a whole series of applications, all built using .Net Framework 4.7.2 and they work just fine - the data is successfully retrieved from the WebAPI.
However....I have one particular application (again, 4.7.2) where the GET consistently fails with the error message:
System.Net.Sockets.SocketException HResult=0x80004005 Message=An existing connection was forcibly closed by the remote host
This exception was originally thrown at this call stack: System.Net.Sockets.Socket.BeginReceive(byte, int, int, System.Net.Sockets.SocketFlags, System.AsyncCallback, object)
So this has to be something specific to my application that consumes this NuGet package since it works for all other consuming applications. However, I can't see how to figure out what the problem might be.
So I found the answer, but I'm confused by it.
I'm using the latest version of Windows 10 (version 1909). All my applications are using .Net 4.7.2
So when I debug all these .NET 4.7.2 applications on my machine, they all make the call to the WebAPI on my IIS LocalHost, except this one application.
When I look at the
ServicePointManager.SecurityProtocol in this failing application, I see it's running with the obsolete values of
TLS. Why would this be the case for this application but not the others? It's not stipulated anywhere to use these obsolete protocols, so why is this using them but not the other applications?
I fixed this by amending my NuGet DLL to add TLS1.2 to whatever TLS versions are being used:
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | ServicePointManager.SecurityProtocol;
User contributions licensed under CC BY-SA 3.0