在 Windows 10(版本 10.0.19041)上运行的 .NET 4.8 应用程序使用注册表启用了 TLS 1.3,按照如何在 Windows 10 中启用 TLS 1.3
但是运行以下代码:
try
{
System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls13;
using (var client = new WebClient())
{
var img = client.DownloadData("URL of an image - Only TLS 1.3 at client side - removed for privacy purposes");
MemoryStream ms = new MemoryStream(img);
Image i = Image.FromStream(ms);
i.Save(AppDomain.CurrentDomain.BaseDirectory+"/img1.jpeg");
}
}
catch(Exception ex)
{
logger.Log(LogLevel.Error, ex.ToString());
}
产生以下 - 异常 StackTrace:
2020-10-05 12:40:52.4779 ERROR System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive. ---> System.IO.IOException: Cannot determine the frame size or a corrupted frame was received.
at System.Net.Security._SslStream.StartFrameBody(Int32 readBytes, Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security._SslStream.StartFrameHeader(Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security._SslStream.StartReading(Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security._SslStream.ProcessRead(Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security._SslStream.Read(Byte[] buffer, Int32 offset, Int32 count)
at System.Net.TlsStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.PooledStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.Connection.SyncRead(HttpWebRequest request, Boolean userRetrievedStream, Boolean probeRead)
我发现了一个与 .NET 5.0 相关的问题,但是我不知道该问题是否已修复或将针对 .NET 4.8 https://github.com/dotnet/runtime/issues/1720修复