Click here to Skip to main content
15,942,800 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I'm kinda new for c# and I've never used HttpClient and since I use it I have random SSL connnection failure. I tried things like adding HttpClientHandler but didn't help, and I don't really know where to "see inner exception" because the program isn't stopping just keeps going like nothing happened.
The error message:
The SSL connection could not be established, see inner exception


What I have tried:

C#
HttpClientHandler clientHandler = new HttpClientHandler();
            clientHandler.ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => { return true; };
            HttpClient client = new HttpClient(clientHandler);
Posted
Updated 25-Aug-19 3:17am
Comments
Richard MacCutchan 25-Aug-19 7:46am    
What does the inner exception tell you?
Citrom67 25-Aug-19 9:09am    
I don't know because I don't know how to read inner exception, the only thing I found about how to check the inner exception is through this "view detail" button but I don't get anything like that.https://i.imgur.com/gp53Em1.png
Richard MacCutchan 25-Aug-19 11:49am    
Well it is something you urgently need to learn. You cannot continue to write code if you do not understand the basics of debugging.

1 solution

C#
try {
...

} catch ( Exception ex ) {
   ...

   if ( ex.InnerException != null ){
     "display" ex.InnerException.Message;
   }
}
 
Share this answer
 
Comments
sencsk 8-Sep-20 2:57am    
Hi Team, I am also facing same exception. here below i posted my inner exception. I have enabled TLS 1.0,1.1 and 1.2 version in server registry.
But no luck


Request and Response: System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception.__ ---> System.Security.Authentication.AuthenticationException: Authentication failed, see inner exception.__ ---> System.ComponentModel.Win32Exception (0x80090326): The message received was unexpected or badly formatted.__ --- End of inner exception stack trace ---__ at System.Net.Security.SslStream.StartSendAuthResetSignal(ProtocolToken message, AsyncProtocolRequest asyncRequest, ExceptionDispatchInfo exception)__ at System.Net.Security.SslStream.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)__ at System.Net.Security.SslStream.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)__ at System.Net.Security.SslStream.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)__ at System.Net.Security.SslStream.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest)__ at System.Net.Security.SslStream.PartialFrameCallback(AsyncProtocolRequest asyncRequest)__--- End of stack trace from previous location where exception was thrown ---__ at System.Net.Security.SslStream.ThrowIfExceptional()__ at System.Net.Security.SslStream.InternalEndProcessAuthentication(LazyAsyncResult lazyResult)__ at System.Net.Security.SslStream.EndProcessAuthentication(IAsyncResult result)__ at System.Net.Security.SslStream.EndAuthenticateAsClient(IAsyncResult asyncResult)__ at System.Net.Security.SslStream.<>c.<authenticateasclientasync>b__65_1(IAsyncResult iar)__ at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)__--- End of stack trace from previous location where exception was thrown ---__ at System.Net.Http.ConnectHelper.EstablishSslConnectionAsyncCore(Stream stream, SslClientAuthenticationOptions sslOptions, CancellationToken cancellationToken)__ --- End of inner exception stack trace ---__ at System.Net.Http.ConnectHelper.EstablishSslConnectionAsyncCore(Stream stream, SslClientAuthenticationOptions sslOptions, CancellationToken cancellationToken)__ at System.Net.Http.HttpConnectionPool.ConnectAsync(HttpRequestMessage request, Boolean allowHttp2, CancellationToken cancellationToken)__ at System.Net.Http.HttpConnectionPool.CreateHttp11ConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken)__ at System.Net.Http.HttpConnectionPool.GetHttpConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken)__ at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken)__ at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)__ at System.Net.Http.DiagnosticsHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)__ at System.Net.Http.HttpClient.FinishSendAsyncBuffered(Task`1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts)
[no name] 8-Sep-20 9:42am    
I says your "authentication" failed; something about a bad message. No use without seeing code. Open your own question and don't piggy-back on "old" (dead) stuff.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900