OData to sandbox or production: the underlying connection was closed
A .NET OData client fails against D365FO sandbox or production with "The underlying connection was closed". The cause is TLS 1.2.
Finance and operations apps support only TLS 1.2, so a client that does not negotiate it still fails.
- First written
- Re-read
- Versions
- D365FO
A .NET client that worked against a development box failed as soon as it pointed to a UAT or production environment, with “The underlying connection was closed: An unexpected error occurred on a send”. The cause was the TLS version negotiated by the client.
Then → now: the full troubleshooting list for TLS errors in .NET clients is in Resolving the “SSL/TLS Secure Channel” Error in .NET Applications.
In D365FO today
The point still holds: “Finance and operations apps support only TLS 1.2. Earlier TLS versions 1.0 and 1.1 aren’t supported.” (Encryption in finance and operations apps). So a client that does not negotiate TLS 1.2 cannot connect.
The original note
As reported in a Dynamics community thread, when you connect to a UAT or production environment with OData, the client reports this error: “The underlying connection was closed: An unexpected error occurred on a send”.
The fix is to add this line before you open the connection:
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
References
- Encryption in finance and operations apps (Microsoft Learn)
- Original community thread (Dynamics Community)