0
votes

Initially my project was on .NET framework 4.5 and then I migrated it to .NET framework 4.6.1 And Now, I am getting Socket Exceptions which was not there earlier with .NET 4.5

Error message as:

Inner Exception --------------- Type : System.ServiceModel.CommunicationException, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 Message : The socket connection was aborted. This could be caused by an error processing your message or a receive timeout being exceeded by the remote host, or an underlying network resource issue. Local socket timeout was '00:00:59.9900000'.

Inner Exception --------------- Type : System.Net.Sockets.SocketException, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 Message : An existing connection was forcibly closed by the remote host

Can anyone please tell, how upgrade in .NET framework is affecting it and what should be the solution?

1
How did you "migrate" the application? Did you just change the target framework of the project? Can you share a minimal reproducible example? - itsme86
There's no problem with 4.6.1. The error complains that the remote server closed the connection. - Panagiotis Kanavos
I changed the target framework of project in Visual Studio under properties -> Application -> Target framework. And then build the application code. - SANKET_121
@PanagiotisKanavos but it works in .NET 4.5 Then why not in 4.6.1 ? - SANKET_121
We don't know, because you won't share code that exhibits the problem. I can guarantee you that others have successfully used sockets in 4.6.1. - itsme86

1 Answers

2
votes

This might be caused from the server/host security settings. To change security settings you set following before calling remote data:

System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;

System.Net.SecurityProtocolType enum contains all options. If you need multiple seperate them with or (|)