如何解决一年后,应用程序现在抛出:System.Net.Sockets.SocketException:现有连接被远程主机强行关闭
我一直在搜索,但是找不到为什么这个问题突然出现的答案。 我有一个4.5.NET C#控制台应用程序,已经运行了一年多,但是现在抛出以下错误:
发生异常:System.Net.WebException
:基础连接已关闭:接收时发生意外错误。 ---> System.IO.IOException
:无法从传输连接读取数据:远程主机强行关闭了现有连接。 ---> System.Net.Sockets.SocketException
:远程主机强行关闭了现有连接
在System.Net.Sockets.NetworkStream.Read(Byte[] buffer,Int32 offset,Int32 size)
---内部异常堆栈跟踪的结尾---
在System.Net.Sockets.NetworkStream.Read(Byte[] buffer,Int32 size)
在System.Net.PooledStream.Read(Byte[] buffer,Int32 size)
在System.Net.Connection.SyncRead(HttpWebRequest request,Boolean userRetrievedStream,Boolean probeRead)
---内部异常堆栈跟踪结束---
at System.Net.HttpWebRequest.GetResponse()
at Microsoft.SharePoint.Client.SPWebRequestExecutor.Execute()
at Microsoft.SharePoint.Client.ClientContext.EnsureFormDigest()
at Microsoft.SharePoint.Client.ClientContext.ExecuteQuery()
at Sharepoint_Audit_Automation.SharepointAudit.returnUsersfromView(String listName,String viewName,ClientContext clientContext,WebClient client,XNamespace d,String recipientField)
at Sharepoint_Audit_Automation.SharepointAudit.Main(String[] args)
尝试执行ClientContext.ExecuteQuery()
时将引发异常。应用程序上的任何内容都没有更改。我正在等待SP服务器团队的响应,以查看他们方面是否有任何更改,但是这里的任何人都不知道是什么原因导致了这个新问题吗?
我正在使用SharePoint Foundation REST。
谢谢。
解决方法
如果使用的是.NET 4.5,则默认的TLS协议为TLSv1。我敢打赌,您的服务器不再支持它,这就是您遇到异常的原因。
解决方案:
-
升级到较新的.NET版本(4.7.2或更高版本)。
-
启用TLSv12协议:
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。