1

I have a program (console application) that makes use of LinqToTwitter to read some tweets. When I debug the program I get an error "The underlying connection was closed: An unexpected error occurred in a submission".

Message = An error occurred while sending the request. Message = The underlying connection was closed: An unexpected send error occurred.

If I build the program, I can run the program without any problems. I already researched and can't find the problem. Does it have to do with TLS 1.2? How do I set up in Visual Studio? I use VS 2015.

Joe Mayo
  • 7,501
  • 7
  • 41
  • 60
DaniloPF
  • 67
  • 7

1 Answers1

2

Now that you mention TLS 1.2 and you're using an older version of Visual Studio, it makes sense. Add this to your Main procedure:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12

Twitter switched to TLS 1.2 a while ago.

Joe Mayo
  • 7,501
  • 7
  • 41
  • 60
  • Thank you! But, I still have doubts: my application is written in VB.net, when I saw your answer, I thought of putting this parameter in app.config, but I didn't find the right place, because within the startup only supportedRuntime and requiredRuntime parameters are recognized. I researched the internet about where to put this parameter and I was also not lucky to find out. Where should I put this parameter? – DaniloPF Apr 01 '20 at 13:37
  • 1
    It isn't a parameter, it's code. I updated the code to explain that this can be in your Main procedure and removed the semi-colon (VB). – Joe Mayo Apr 01 '20 at 15:55
  • Thanks! It worked perfectly, now I can debug the program without abend. By the way, in the other question, I couldn't mark your answer as a solution, I think it was because it came as a comment and not an answer! – DaniloPF Apr 01 '20 at 19:42
  • 1
    I created an answer over there that refers to this one - assuming they're the same issue. – Joe Mayo Apr 01 '20 at 23:13