20

Are there any known issues with using RestSharp & TLS 1.1? We currently use RestSharp to send post requests to a vendor. This vendor is no longer going to accept TLS 1.0 connections and changing to TLS 1.1.

The problem is when they switch from TLS 1.0 to TLS 1.1 then the RestSharp code we have no longer works.

I've tested this on 2008 R2 (after enabling registry settings for 1.1 and 1.2) and also on Windows 8.1. They switch to TLS 1.1 and the RestResponse is:

"The underlying connection was closed: An unexpected error occurred on a send"

Switch back to TLS 1.0 and no problem. I've tested access their site using Google Chrome and it does show TLS 1.1 so the server and client workstation are able to use TLS 1.1. It just seems to be RestSharp that is the issue...

Jacob Dixon
  • 201
  • 1
  • 2
  • 4

3 Answers3

40

I haven't found any way to configure RestSharp to use different protocol. But you can override default protocol in ServicePointManager before making requests:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11;

This solve the issue. You can also change Windows Registry settings to use TLS 1.1/1.2 by default. Here is more info in related question.

Community
  • 1
  • 1
Vladislav Kostenko
  • 1,155
  • 11
  • 18
  • 2
    FYI, this requires .NET 4.5 or higher, which won't run on XP/Server 2003. (doesn't affect OP, but worth noting) – ps2goat Mar 30 '16 at 13:13
  • This answer does not work for me. Running on .net 4.5.2 and it still fails – emirhosseini Jul 15 '16 at 17:11
  • 8
    To whom it may concern: `ServicePointManager` object comes from `System.Net` namespace, and maintains a static-like state. So, only "using" that namespace & execute the answered code *once* before executing concerned operation(s) does the trick. – kmonsoor Aug 16 '16 at 12:49
3

RestSharp already documented this issue:

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;

Therefore, consider adding the line above at Program.cs.

-5

Simple fix is to update your project to latest .Net Framework.

Hemz
  • 1
  • 1