Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.0k views
in Technique[技术] by (71.8m points)

c# - net 5.0 Cannot determine the frame size or a corrupted frame was received

I want to try net5.0 since it's in rc2, and I've encountered a strange issue.

I've created a default WebApi in net5.0. I didn't touch anything, I just clicked run (in kestrel, not ISS) and the Swagger home page shows up. I tried the WeatherForcast get and everything is working fine.

Swagger index page

then I created a console app in NET5.0 and added this code :

static async Task Main(string[] args)
{
    var clientHandler = new HttpClientHandler
    {
        ServerCertificateCustomValidationCallback = (_, _, _, _) => true
    };
    var client = new HttpClient(clientHandler);
    try
    {
        var httpMessage = await client.GetAsync("https://localhost:5001/WeatherForecast");
    }
    catch (Exception e)
    {
        Console.WriteLine(e);
        throw;
    }
}

and with this code I got the following error :

System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception.
---> System.IO.IOException: Cannot determine the frame size or a corrupted frame was received.

after that, I tried on Postman the same request and it worked (as from swagger). My final test was to switch the console app to netcore 3.1 and the request worked.

So I only got this error on net5.0 app.

Any suggestions ?

EDIT :

  • Here are my pc info : W10 Enterprise, V 1809, Build 17763.1518.
  • I only got the error on the Net5.0 console.
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Kestrel used to force selection of Tls 1.1 or Tls 1.2. From .Net 5.0 Preview 6 onwards, it was change to "None", meaning the OS default. Kestrel Default Tls Support

Coincidentally, Microsoft last year started enabling Tls 1.3 by default in Windows 10. Windows 10 Tls 1.3 Enabled by DefaultHence your application is likely now using Tls 1.3 which I have found to be sometimes "problematic".

To set Tls 1.3 to be disabled by default (meaning available to apps that request it, but off otherwise), in your registry go to or create this path:

HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlSecurityProvidersSCHANNELProtocolsTLS 1.3Client

And set or create a DWORD named DisabledByDefault to 1.

This should make your browser go with Tls 1.2.

For your Kestrel server, similarly:

HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlSecurityProvidersSCHANNELProtocolsTLS 1.3Server

Also there, set or create a DWORD named DisabledByDefault to 1.

If that doesn't do it, under both Client and Server also create a DWORD named "Enabled" set to 0. This will disable Tls 1.3 altogether.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...