Click here to Skip to main content
15,888,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Ever since I made my discord bot I get the same error over and over again, no matter what I do in the code! I get this error message when I use httpclien/webclient and I get it even when I don't use it!
Quote:
SSL connection could not be established, see inner exception

Authentication failed, see inner exception. System.Private.CoreLib

The the message received was unexpected or badly formatted


I have no idea what causes this problem and I couldn't find anything about this error in particular.

[Command("avatar")]
       public async Task Avatar(SocketGuildUser mention = null)
       {
           try
           {
               if (mention is null)
               {
                   string url = Context.User.GetAvatarUrl(format: ImageFormat.Auto,2048).ToString();

                   EmbedBuilder builder = new EmbedBuilder();
                   builder.WithTitle("Here you go!").WithImageUrl($"{url}");

                   await ReplyAsync($"", false, builder.Build());
               }
               else
               {
                   string url = mention.GetAvatarUrl(format: ImageFormat.Auto, 2048).ToString();
                   EmbedBuilder builder = new EmbedBuilder();
                   builder.WithTitle("Here you go!").WithImageUrl($"{url}");

                   await ReplyAsync($"", false, builder.Build());
               }
           }
           catch (Exception ex)
           {
               Console.WriteLine(ex.Message);
               if (ex.InnerException != null)
               {
                   Console.WriteLine(ex.InnerException.Message + " " + ex.InnerException.Source);
               }
               if (ex.InnerException.InnerException.Message != null)
               {
                   Console.WriteLine(ex.InnerException.InnerException.Message);
               }
           }

       }


And even with this simple code I got the error message twice and I really do not see what's wrong.

What I have tried:

I tried using http client authentication but the error still remains.
And it's completely random, like 1-3 time out of 20 it happens but the other times it's completely fine and works just as you'd expect
Posted
Updated 31-Aug-19 4:39am
v2
Comments
Richard MacCutchan 31-Aug-19 7:08am    
Look at the error message: "The the message received was unexpected or badly formatted". So you need to examine the messages that are being sent to the remote system.
Citrom67 31-Aug-19 7:12am    
I know I am dumb but this is new for me so could you give a clue how to do that?
Richard MacCutchan 31-Aug-19 7:39am    
No, because I have no idea what your code is trying to do. If you want to learn bout seciure HTTP there are many resources that Google will find for you.
Citrom67 31-Aug-19 7:48am    
Alright then, thanks for your help
Richard MacCutchan 31-Aug-19 8:01am    
You could start by using the debugger to step through the code and examine every variable as you go. That would at least let you see some of the data that is being transferred.

1 solution

If you are using an older .NET framework version, or older Windows version, you can run into TLS problems. See article here: Solving the TLS 1.0 Problem - Security documentation | Microsoft Docs[^]
The simplest solution is often to use a newer .NET framework version.
 
Share this answer
 

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