brandonseydel/MailChimp.Net

The request was aborted: Could not create SSL/TLS secure channel

Closed this issue · 10 comments

Our organization has been using this API wrapper for the past 3 years or so and haven't had any issues until about 2 or 3 weeks ago. For the last couple of weeks we have been getting the error in the title when simply attempting to retrieve MailChimp list results. Here's where the code errors:

`MailChimp.Net.MailChimpManager mcUHFManager = new MailChimp.Net.MailChimpManager(new MailChimp.Net.MailChimpConfiguration { ApiKey = mcUHFAPIKey, Limit = 100 });
			MailChimp.Net.MailChimpManager mcAGManager = new MailChimp.Net.MailChimpManager(new MailChimp.Net.MailChimpConfiguration { ApiKey = mcAGAPIKey, Limit = 100 });

IEnumerable<MailChimp.Net.Models.List> uhfListResults = mcUHFManager.Lists.GetAllAsync().Result;`

The error occurs on the GetAllAsync line in the Stack Trace. I have not made any updates to our application and am pretty sure things over at MailChimp are fine. I am not sure where to go from here. I did see this issue from a previous API wrapper we used for MailChimp v2.0 [(https://github.com/danesparza/MailChimp.NET/issues/163)]. I did go to the MailChimp API Reference pags and it looks very different now. It also looks as though there are 2 variations of API one for marketing and one for transactional. I'm not really sure what's going on. I didn't get any warning from MailChimp that they were going to change their API like we did when they were going from 2.0 to 3.0.

Hmm do you have that stack somewhere?

This is the stack when I run it from VS:

Server Error in '/' Application.

The request was aborted: Could not create SSL/TLS secure channel.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Net.WebException: The request was aborted: Could not create SSL/TLS secure channel.

Source Error:

Line 362: MailChimp.Net.MailChimpManager mcAGManager = new MailChimp.Net.MailChimpManager(new MailChimp.Net.MailChimpConfiguration { ApiKey = mcAGAPIKey, Limit = 100 });
Line 363:
Line 364: IEnumerable<MailChimp.Net.Models.List> uhfListResults = mcUHFManager.Lists.GetAllAsync().Result;
Line 365: IEnumerable<MailChimp.Net.Models.List> agListResults = mcAGManager.Lists.GetAllAsync().Result;
Line 366:

Source File: \uhffs1\home$\CheungJ\Visual Studio 2013\Projects\MailChimpAPI\MailChimpAPI\Controllers\HomeController.cs Line: 364

Stack Trace:

[WebException: The request was aborted: Could not create SSL/TLS secure channel.]
System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult) +638
System.Net.Http.HttpClientHandler.GetResponseCallback(IAsyncResult ar) +65

[HttpRequestException: An error occurred while sending the request.]
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +102
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +64
System.Runtime.CompilerServices.ConfiguredTaskAwaiter.GetResult() +29
MailChimp.Net.Logic.d__4.MoveNext() +652
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +102
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +64
System.Runtime.CompilerServices.ConfiguredTaskAwaiter.GetResult() +29
MailChimp.Net.Logic.d__3.MoveNext() +292

[AggregateException: One or more errors occurred.]
System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions) +4247162
System.Threading.Tasks.Task1.GetResultCore(Boolean waitCompletionNotification) +12576124 System.Threading.Tasks.Task1.get_Result() +34
MailChimpAPI.Controllers.HomeController.UnsubscribedEmails(String listId, String buttonType) in \uhffs1\home$\CheungJ\Visual Studio 2013\Projects\MailChimpAPI\MailChimpAPI\Controllers\HomeController.cs:364
lambda_method(Closure , ControllerBase , Object[] ) +245
System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +59
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary2 parameters) +437 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary2 parameters) +60
System.Web.Mvc.Async.ActionInvocation.InvokeSynchronousActionMethod() +76
System.Web.Mvc.Async.AsyncControllerActionInvoker.b__39(IAsyncResult asyncResult, ActionInvocation innerInvokeState) +36
System.Web.Mvc.Async.WrappedAsyncResult2.CallEndDelegate(IAsyncResult asyncResult) +73 System.Web.Mvc.Async.WrappedAsyncResultBase1.End() +137
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +102
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +49
System.Web.Mvc.Async.AsyncInvocationWithFilters.b__3d() +117
System.Web.Mvc.Async.<>c__DisplayClass46.b__3f() +323
System.Web.Mvc.Async.<>c__DisplayClass33.b__32(IAsyncResult asyncResult) +44
System.Web.Mvc.Async.WrappedAsyncResult1.CallEndDelegate(IAsyncResult asyncResult) +47 System.Web.Mvc.Async.WrappedAsyncResultBase1.End() +137
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +102
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +50
System.Web.Mvc.Async.<>c__DisplayClass2b.b__1c() +72
System.Web.Mvc.Async.<>c__DisplayClass21.b__1e(IAsyncResult asyncResult) +185
System.Web.Mvc.Async.WrappedAsyncResult1.CallEndDelegate(IAsyncResult asyncResult) +42 System.Web.Mvc.Async.WrappedAsyncResultBase1.End() +134
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +56
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +40
System.Web.Mvc.Controller.b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +34
System.Web.Mvc.Async.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult asyncResult) +70 System.Web.Mvc.Async.WrappedAsyncResultBase1.End() +134
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +56
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +37
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +44
System.Web.Mvc.Controller.b__15(IAsyncResult asyncResult, Controller controller) +39
System.Web.Mvc.Async.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult asyncResult) +62 System.Web.Mvc.Async.WrappedAsyncResultBase1.End() +134
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +56
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +37
System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +39
System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +39
System.Web.Mvc.MvcHandler.b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +39
System.Web.Mvc.Async.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult asyncResult) +70 System.Web.Mvc.Async.WrappedAsyncResultBase1.End() +134
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +56
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +37
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +40
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +38
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9836613
System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +50
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +163

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.8.4075.0

I had the same exception. But it has nothing to do with this library. I was able to fix it with
ServicePointManager.SecurityProtocol = ServicePointManager.SecurityProtocol | SecurityProtocolType.Tls12;

It looks like MailChimp requires TLS 1.2

@mikehachen Thank you, that worked. I did see that in a issue post for a MailChimp 2.0 wrapper we used to use but I wasn't sure if that was just a 2.0 problem. It's weird out application has worked the past couple of years with this library not having run into this exception until just 2 or 3 weeks ago.

We had this issue too.

@mikehachen 's solution worked for us aswell.

Odd that we haven't heard anything from MailChimp.

I don't think that this issue has nothing to do with this library. This library only works with servers that require TLS 1.2 (as of recently).

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

Should be added in somewhere in the code instead of every application that uses this library needing to add it in.

No, this is not a good idea! Please read this MSDN-Article. It says

To ensure .NET Framework applications remain secure, the TLS version should not be hardcoded. .NET Framework applications should use the TLS version the operating system (OS) supports.

I strongly do not recommend hardcoding the TLS version into the library!

Thanks for finding more information about this issue on MSDN. Always good to have more information to make a better decision.

The article says to use .NET 4.7 as the answer. This SDK still has 4.5 as a target.

Looks like it's been 2 months now that this library has not worked with MailChimp servers and .NET 4.5 without forcing TLS 1.2 using the above code.

The operating system supports it, but for some reason is not using it. Why? Maybe a bug in .NET? Maybe some hidden configuration is needed for .NET 4.5 to know to use TLS 1.2 on Windows 10 and Windows Server 2019?

Whatever the reason, it seems like it should be included, regardless if whether it's considered a bad idea. If not included, at lest it should be documented that it's needed to be added to the application using it for .NET 4.5 to interact with Mailchimp API servers.

I agree with you that it should at least be documented. However, I still believe that it should not be fixed implemented in the code. In my opinion, the version of TLS used should never be hard coded in a library. I'll create a PR with an updated readme.md

I think that would be great! Thanks for adding it!