I've got a problem in my Xamarin Project: When I try to get a JsonString from a Webpage, via HttpClient.GetStringAsncy does my app crash. Here is the StackTrace of the error:
at System.Net.Http.HttpClientHandler+d__63.MoveNext () [0x00479] in :0
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in :0
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in :0
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in :0
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in :0
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[TResult].GetResult () [0x00000] in :0
at System.Net.Http.HttpClient+d__49.MoveNext () [0x000ca] in :0
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in :0
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in :0
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in :0
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in :0
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[TResult].GetResult () [0x00000] in :0
at System.Net.Http.HttpClient+d__54.MoveNext () [0x0007d] in :0
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in :0
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in :0
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in :0
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in :0
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[TResult].GetResult () [0x00000] in :0
at MRKrauchthal.Pages.GameDetailPage+d__13.MoveNext () [0x00057] in E:\Visual Studio Projects\MRKrauchthal\MRKrauchthal\MRKrauchthal\Pages\GameDetailPage.xaml.cs:99
e.InnerException
{System.Net.WebException: Error: SecureChannelFailure (The authentication or decryption has failed.) ---> System.IO.IOException: The authentication or decryption has failed. ---> System.IO.IOException: The authentication or decryption has failed. ---> Mono.Security.Protocol.Tls.TlsException: The authentication or decryption has failed.
at Mono.Security.Protocol.Tls.RecordProtocol.EndReceiveRecord (System.IAsyncResult asyncResult) [0x00037] in :0
at Mono.Security.Protocol.Tls.SslClientStream.SafeEndReceiveRecord (System.IAsyncResult ar, System.Boolean ignoreEmpty) [0x00000] in :0
at Mono.Security.Protocol.Tls.SslClientStream.NegotiateAsyncWorker (System.IAsyncResult result) [0x00071] in :0
--- End of inner exception stack trace ---
at Mono.Security.Protocol.Tls.SslClientStream.EndNegotiateHandshake (System.IAsyncResult result) [0x00032] in :0
at Mono.Security.Protocol.Tls.SslStreamBase.AsyncHandshakeCallback (System.IAsyncResult asyncResult) [0x0000c] in :0
--- End of inner exception stack trace ---
at Mono.Security.Protocol.Tls.SslStreamBase.EndRead (System.IAsyncResult asyncResult) [0x0004b] in :0
at Mono.Net.Security.Private.LegacySslStream.EndAuthenticateAsClient (System.IAsyncResult asyncResult) [0x0000e] in :0
at Mono.Net.Security.Private.LegacySslStream.AuthenticateAsClient (System.String targetHost, System.Security.Cryptography.X509Certificates.X509CertificateCollection clientCertificates, System.Security.Authentication.SslProtocols enabledSslProtocols, System.Boolean checkCertificateRevocation) [0x0000e] in :0
at Mono.Net.Security.MonoTlsStream.CreateStream (System.Byte[] buffer) [0x0007b] in :0
at System.Net.WebConnection.CreateStream (System.Net.HttpWebRequest request) [0x00073] in :0
--- End of inner exception stack trace ---
at System.Net.HttpWebRequest.EndGetResponse (System.IAsyncResult asyncResult) [0x00058] in :0
at System.Threading.Tasks.TaskFactory`1[TResult].FromAsyncCoreLogic (System.IAsyncResult iar, System.Func`2[T,TResult] endFunction, System.Action`1[T] endAction, System.Threading.Tasks.Task`1[TResult] promise, System.Boolean requiresSynchronization) [0x0000f] in :0
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in :0
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in :0
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in :0
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in :0
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[TResult].GetResult () [0x00000] in :0
at System.Net.Http.HttpClientHandler+d__63.MoveNext () [0x0041e] in :0 }
The Code looks like this:
private async Task SetImage(int id, string teamName, Xamarin.Forms.Image image)
{
try
{
HttpClient httpClient = new HttpClient();
obj = JsonConvert.DeserializeObject<JsonImage>(await httpClient.GetStringAsync("www.linkToImage.com").ConfigureAwait(false));
}
catch (Exception e) {
test.Text = e.StackTrace;
}
}
I hope someone can help me :D
Best Regards
There is some problem with the default SSL/TLS implementation in Xamarin.Android. You can go to Android Project settings->Android Options->Advanced->SSL/TLS implementation and change to Native TLS 1.2+
Related
Im building an xamarin app and am Im trying to post to Web api with IP address of http://192.168.1.108:51457/api/Home. the api already accepts this ip address.i.e. I can run the api from that uri.I also know that the web api can recieve post request.
Not sure if connection is being refused because the IP address is logically inaccessible or there is some authorisation required. is there a solution to this?
stack trace:
at System.Net.Http.HttpClientHandler+<SendAsync>d__63.MoveNext () [0x004ab] in <7736395a6c71409691a34accfc621095>:0
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <896ad1d315ca4ba7b117efb8dacaedcf>:0
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in <896ad1d315ca4ba7b117efb8dacaedcf>:0
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <896ad1d315ca4ba7b117efb8dacaedcf>:0
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <896ad1d315ca4ba7b117efb8dacaedcf>:0
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[TResult].GetResult () [0x00000] in <896ad1d315ca4ba7b117efb8dacaedcf>:0
at System.Net.Http.HttpClient+<SendAsyncWorker>d__49.MoveNext () [0x000ca] in <7736395a6c71409691a34accfc621095>:0
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <896ad1d315ca4ba7b117efb8dacaedcf>:0
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in <896ad1d315ca4ba7b117efb8dacaedcf>:0
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <896ad1d315ca4ba7b117efb8dacaedcf>:0
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <896ad1d315ca4ba7b117efb8dacaedcf>:0
at System.Runtime.CompilerServices.TaskAwaiter`1[TResult].GetResult () [0x00000] in <896ad1d315ca4ba7b117efb8dacaedcf>:0
at App.Registration+<RegistrationFrom>d__1.MoveNext () [0x00184] in C:\Users\User\source\repos\App\App\App\Registration.xaml.cs:49
inner Exception: `**Error: ConnectFailure (Connection refused)"**`
at System.Net.HttpWebRequest.EndGetRequestStream (System.IAsyncResult asyncResult) [0x0003a] in <6c708cf596db438ebfc6b7e012659eee>:0
at System.Threading.Tasks.TaskFactory`1[TResult].FromAsyncCoreLogic (System.IAsyncResult iar, System.Func`2[T,TResult] endFunction, System.Action`1[T] endAction, System.Threading.Tasks.Task`1[TResult] promise, System.Boolean requiresSynchronization) [0x0000f] in <896ad1d315ca4ba7b117efb8dacaedcf>:0
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <896ad1d315ca4ba7b117efb8dacaedcf>:0
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in <896ad1d315ca4ba7b117efb8dacaedcf>:0
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <896ad1d315ca4ba7b117efb8dacaedcf>:0
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <896ad1d315ca4ba7b117efb8dacaedcf>:0
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[TResult].GetResult () [0x00000] in <896ad1d315ca4ba7b117efb8dacaedcf>:0
at System.Net.Http.HttpClientHandler+<SendAsync>d__63.MoveNext () [0x002e7] in <7736395a6c71409691a34accfc621095>:0
I am trying to make a SOAP request and I am catching an Exception, you can see it below. (I am not consuming WCF)
Maybe someone had similar issues and knows how to solve it? Thanks in advance.
{System.ArgumentException: The empty string '' is not a valid local name.
at (wrapper managed-to-native) System.Object:__icall_wrapper_mono_delegate_end_invoke (object,intptr)
at (wrapper delegate-end-invoke) :end_invoke_object__this___object[]&_IAsyncResult (object[]&,System.IAsyncResult)
at System.ServiceModel.MonoInternal.ClientRuntimeChannel.EndProcess (System.Reflection.MethodBase method, System.String operationName, System.Object[] parameters, System.IAsyncResult result) [0x0001f] in <475dec2c1fe44b95bbfbd21b550b63f8>:0
at System.ServiceModel.ClientBase1+ChannelBase1[TChannel,T].EndInvoke (System.String methodName, System.Object[] args, System.IAsyncResult result) [0x00045] in <475dec2c1fe44b95bbfbd21b550b63f8>:0
at App3.AscoTms.imcwpPortTypeClient+imcwpPortTypeClientChannel.EndLogin (System.IAsyncResult result) [0x00008] in C:\Users\georgij.nebudrov\source\repos\App3\App3\App3\Connected Services\AscoTms\Reference.cs:3833
at App3.AscoTms.imcwpPortTypeClient.App3.AscoTms.imcwpPortType.EndLogin (System.IAsyncResult result) [0x00001] in C:\Users\georgij.nebudrov\source\repos\App3\App3\App3\Connected Services\AscoTms\Reference.cs:3088
at App3.AscoTms.imcwpPortTypeClient.EndLogin (System.IAsyncResult result) [0x00001] in C:\Users\georgij.nebudrov\source\repos\App3\App3\App3\Connected Services\AscoTms\Reference.cs:3093
at App3.AscoTms.imcwpPortTypeClient.OnEndLogin (System.IAsyncResult result) [0x00001] in C:\Users\georgij.nebudrov\source\repos\App3\App3\App3\Connected Services\AscoTms\Reference.cs:3103
at System.ServiceModel.ClientBase1+<>c__DisplayClass39_0[TChannel].<InvokeAsync>b__0 (System.IAsyncResult ar) [0x00006] in <475dec2c1fe44b95bbfbd21b550b63f8>:0
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <896ad1d315ca4ba7b117efb8dacaedcf>:0
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in <896ad1d315ca4ba7b117efb8dacaedcf>:0
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <896ad1d315ca4ba7b117efb8dacaedcf>:0
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <896ad1d315ca4ba7b117efb8dacaedcf>:0
at System.Runtime.CompilerServices.TaskAwaiter1[TResult].GetResult () [0x00000] in <896ad1d315ca4ba7b117efb8dacaedcf>:0
at App3.MainPage+d__2.MoveNext () [0x00081] in C:\Users\georgij.nebudrov\source\repos\App3\App3\App3\MainPage.xaml.cs:47 }
I created a simple Xamarin.Forms App to check HTTPS using https://jsonplaceholder.typicode.com/.
But the App crashes using HTTPS.
public RestService() {
client = new HttpClient();
client.MaxResponseContentBufferSize = 256000;
}
public async Task<List<Item>> RefreshDataAsync() {
string url = "http://jsonplaceholder.typicode.com/posts";
// Crash using this URL
//string url = "https://jsonplaceholder.typicode.com/posts";
var uri = new Uri(string.Format(url, string.Empty));
List<Item> Items = new List<Item>();
var content = await client.GetStringAsync(uri);
Items = JsonConvert.DeserializeObject<List<Item>>(content);
return Items;
}
}
Is it a problem with the website or httpClient or do I do somethin wrong ?
Thats the Exception
{System.Net.Http.HttpRequestException: An error occurred while sending the request ---> System.Net.WebException: Error: SecureChannelFailure (The authentication or decryption has failed.) ---> System.IO.IOException: The authentication or decryption has failed. ---> System.IO.IOException: The authentication or decryption has failed. ---> Mono.Security.Protocol.Tls.TlsException: The authentication or decryption has failed.
at Mono.Security.Protocol.Tls.RecordProtocol.EndReceiveRecord (System.IAsyncResult asyncResult) [0x00037] in <d2bf9ddce2b945f79db1e7c4354bafea>:0
at Mono.Security.Protocol.Tls.SslClientStream.SafeEndReceiveRecord (System.IAsyncResult ar, System.Boolean ignoreEmpty) [0x00000] in <d2bf9ddce2b945f79db1e7c4354bafea>:0
at Mono.Security.Protocol.Tls.SslClientStream.NegotiateAsyncWorker (System.IAsyncResult result) [0x00071] in <d2bf9ddce2b945f79db1e7c4354bafea>:0
--- End of inner exception stack trace ---
at Mono.Security.Protocol.Tls.SslClientStream.EndNegotiateHandshake (System.IAsyncResult result) [0x00032] in <d2bf9ddce2b945f79db1e7c4354bafea>:0
at Mono.Security.Protocol.Tls.SslStreamBase.AsyncHandshakeCallback (System.IAsyncResult asyncResult) [0x0000c] in <d2bf9ddce2b945f79db1e7c4354bafea>:0
--- End of inner exception stack trace ---
at Mono.Security.Protocol.Tls.SslStreamBase.EndRead (System.IAsyncResult asyncResult) [0x0004b] in <d2bf9ddce2b945f79db1e7c4354bafea>:0
at Mono.Net.Security.Private.LegacySslStream.EndAuthenticateAsClient (System.IAsyncResult asyncResult) [0x0000e] in <a547bd0d78184f26ab08d022f013c1e1>:0
at Mono.Net.Security.Private.LegacySslStream.AuthenticateAsClient (System.String targetHost, System.Security.Cryptography.X509Certificates.X509CertificateCollection clientCertificates, System.Security.Authentication.SslProtocols enabledSslProtocols, System.Boolean checkCertificateRevocation) [0x0000e] in <a547bd0d78184f26ab08d022f013c1e1>:0
at Mono.Net.Security.MonoTlsStream.CreateStream (System.Byte[] buffer) [0x0007b] in <a547bd0d78184f26ab08d022f013c1e1>:0
at System.Net.WebConnection.CreateStream (System.Net.HttpWebRequest request) [0x00073] in <a547bd0d78184f26ab08d022f013c1e1>:0
--- End of inner exception stack trace ---
at System.Net.HttpWebRequest.EndGetResponse (System.IAsyncResult asyncResult) [0x00058] in <a547bd0d78184f26ab08d022f013c1e1>:0
at System.Threading.Tasks.TaskFactory`1[TResult].FromAsyncCoreLogic (System.IAsyncResult iar, System.Func`2[T,TResult] endFunction, System.Action`1[T] endAction, System.Threading.Tasks.Task`1[TResult] promise, System.Boolean requiresSynchronization) [0x0000f] in <3fd174ff54b146228c505f23cf75ce71>:0
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <3fd174ff54b146228c505f23cf75ce71>:0
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in <3fd174ff54b146228c505f23cf75ce71>:0
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <3fd174ff54b146228c505f23cf75ce71>:0
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <3fd174ff54b146228c505f23cf75ce71>:0
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[TResult].GetResult () [0x00000] in <3fd174ff54b146228c505f23cf75ce71>:0
at System.Net.Http.HttpClientHandler+<SendAsync>d__63.MoveNext () [0x003e6] in <b696532a7c264e5e866cb15a1b40a4a4>:0
--- End of inner exception stack trace ---
at System.Net.Http.HttpClientHandler+<SendAsync>d__63.MoveNext () [0x00449] in <b696532a7c264e5e866cb15a1b40a4a4>:0
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <3fd174ff54b146228c505f23cf75ce71>:0
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in <3fd174ff54b146228c505f23cf75ce71>:0
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <3fd174ff54b146228c505f23cf75ce71>:0
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <3fd174ff54b146228c505f23cf75ce71>:0
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[TResult].GetResult () [0x00000] in <3fd174ff54b146228c505f23cf75ce71>:0
at System.Net.Http.HttpClient+<SendAsyncWorker>d__49.MoveNext () [0x000ca] in <b696532a7c264e5e866cb15a1b40a4a4>:0
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <3fd174ff54b146228c505f23cf75ce71>:0
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in <3fd174ff54b146228c505f23cf75ce71>:0
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <3fd174ff54b146228c505f23cf75ce71>:0
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <3fd174ff54b146228c505f23cf75ce71>:0
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[TResult].GetResult () [0x00000] in <3fd174ff54b146228c505f23cf75ce71>:0
at System.Net.Http.HttpClient+<GetStringAsync>d__55.MoveNext () [0x0007d] in <b696532a7c264e5e866cb15a1b40a4a4>:0
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <3fd174ff54b146228c505f23cf75ce71>:0
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in <3fd174ff54b146228c505f23cf75ce71>:0
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <3fd174ff54b146228c505f23cf75ce71>:0
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <3fd174ff54b146228c505f23cf75ce71>:0
at System.Runtime.CompilerServices.TaskAwaiter`1[TResult].GetResult () [0x00000] in <3fd174ff54b146228c505f23cf75ce71>:0
at getWeather.RestService+<RefreshDataAsync>d__2.MoveNext () [0x0006e] in C:\Users\afelde\documents\visual studio 2017\Projects\getWeather\getWeather\getWeather\RestService.cs:30 }
That Post on Xamarin.Forum also solve the Issue without installing any Nuget Packages :
As #SvetlomirKalitsov describes, the two settings below take care of
the issue:
HttpClient implementation -> AndroidClientHandler SSL/TLS
implementation -> Native TLS 1Here is where I made the mistake: There
are two pretty similar options: Native TLS 1.2+ which is the correct
one, and Default (Native TLS 1.2+). This second one (Default) will
fail. Make sure to select the non-default one; in other words, make
sure to force that option instead of relying on the Default.
A bit of background info: XA_HTTP_CLIENT_HANDLER_TYPE environment
variable on Xamarin.Android
Thanks #SvetlomirKalitsov
I found a post about your issue (https://forums.xamarin.com/discussion/10405/the-authentication-or-decryption-has-failed-in-the-web-request)
Here in the comments you will find someone suggesting to use the package modernhttpclient
The way to work with this package:
HttpClient client = new HttpClient(new NativeMessageHandler());
The NativeMessagehandler will solve the certifcations issue ( since u using https it gave a authentication error, this will solve it)
For the rest you can use the client as you were already using it.
Good luck
I'm trying to get a discord bot coded in discord.net running on a linux VPS, I'm running via mono but I keep getting this error
Unhandled Exception:
System.Exception: Connection lost
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () <0x7f0ad80016d0 + 0x00029> in <filename unknown>:0
at Discord.TaskManager.ThrowException () <0x419160b0 + 0x00065> in <filename unknown>:0
at Discord.Net.WebSockets.WebSocket.WaitForConnection (CancellationToken cancelToken) <0x4192a2a0 + 0x000af> in <filename unknown>:0
at Discord.Net.WebSockets.GatewaySocket.WaitForConnection (CancellationToken cancelToken) <0x4192a1b0 + 0x000c3> in <filename unknown>:0
at Discord.DiscordClient+<BeginConnect>d__78.MoveNext () <0x41836df0 + 0x01406> in <filename unknown>:0
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () <0x7f0ad80016d0 + 0x00029> in <filename unknown>:0
at Discord.DiscordClient+<BeginConnect>d__78.MoveNext () <0x41836df0 + 0x01abe> in <filename unknown>:0
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () <0x7f0ad80016d0 + 0x00029> in <filename unknown>:0
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) <0x7f0ad7fff6b0 + 0x000a7> in <filename unknown>:0
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) <0x7f0ad7fff630 + 0x0006b> in <filename unknown>:0
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) <0x7f0ad7fff5e0 + 0x0003a> in <filename unknown>:0
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable+ConfiguredTaskAwaiter.GetResult () <0x7f0ad7fffb10 + 0x00012> in <filename unknown>:0
at Discord.DiscordClient+<Connect>d__77.MoveNext () <0x41836560 + 0x002b1> in <filename unknown>:0
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () <0x7f0ad80016d0 + 0x00029> in <filename unknown>:0
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) <0x7f0ad7fff6b0 + 0x000a7> in <filename unknown>:0
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) <0x7f0ad7fff630 + 0x0006b> in <filename unknown>:0
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) <0x7f0ad7fff5e0 + 0x0003a> in <filename unknown>:0
at System.Runtime.CompilerServices.TaskAwaiter.GetResult () <0x7f0ad7fff5c0 + 0x00012> in <filename unknown>:0
at MiXBot.Program+<>c+<<Main>b__1_3>d.MoveNext () <0x41835e40 + 0x001bd> in <filename unknown>:0
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () <0x7f0ad80016d0 + 0x00029> in <filename unknown>:0
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) <0x7f0ad7fff6b0 + 0x000a7> in <filename unknown>:0
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) <0x7f0ad7fff630 + 0x0006b> in <filename unknown>:0
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) <0x7f0ad7fff5e0 + 0x0003a> in <filename unknown>:0
at System.Runtime.CompilerServices.TaskAwaiter.GetResult () <0x7f0ad7fff5c0 + 0x00012> in <filename unknown>:0
at Discord.DiscordClient.ExecuteAndWait (System.Func`1 asyncAction) <0x41835b00 + 0x00086> in <filename unknown>:0
at MiXBot.Program.Main (System.String[] args) <0x417fbf60 + 0x002a3> in <filename unknown>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.Exception: Connection lost
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () <0x7f0ad80016d0 + 0x00029> in <filename unknown>:0
at Discord.TaskManager.ThrowException () <0x419160b0 + 0x00065> in <filename unknown>:0
at Discord.Net.WebSockets.WebSocket.WaitForConnection (CancellationToken cancelToken) <0x4192a2a0 + 0x000af> in <filename unknown>:0
at Discord.Net.WebSockets.GatewaySocket.WaitForConnection (CancellationToken cancelToken) <0x4192a1b0 + 0x000c3> in <filename unknown>:0
at Discord.DiscordClient+<BeginConnect>d__78.MoveNext () <0x41836df0 + 0x01406> in <filename unknown>:0
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () <0x7f0ad80016d0 + 0x00029> in <filename unknown>:0
at Discord.DiscordClient+<BeginConnect>d__78.MoveNext () <0x41836df0 + 0x01abe> in <filename unknown>:0
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () <0x7f0ad80016d0 + 0x00029> in <filename unknown>:0
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) <0x7f0ad7fff6b0 + 0x000a7> in <filename unknown>:0
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) <0x7f0ad7fff630 + 0x0006b> in <filename unknown>:0
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) <0x7f0ad7fff5e0 + 0x0003a> in <filename unknown>:0
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable+ConfiguredTaskAwaiter.GetResult () <0x7f0ad7fffb10 + 0x00012> in <filename unknown>:0
at Discord.DiscordClient+<Connect>d__77.MoveNext () <0x41836560 + 0x002b1> in <filename unknown>:0
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () <0x7f0ad80016d0 + 0x00029> in <filename unknown>:0
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) <0x7f0ad7fff6b0 + 0x000a7> in <filename unknown>:0
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) <0x7f0ad7fff630 + 0x0006b> in <filename unknown>:0
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) <0x7f0ad7fff5e0 + 0x0003a> in <filename unknown>:0
at System.Runtime.CompilerServices.TaskAwaiter.GetResult () <0x7f0ad7fff5c0 + 0x00012> in <filename unknown>:0
at MiXBot.Program+<>c+<<Main>b__1_3>d.MoveNext () <0x41835e40 + 0x001bd> in <filename unknown>:0
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () <0x7f0ad80016d0 + 0x00029> in <filename unknown>:0
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) <0x7f0ad7fff6b0 + 0x000a7> in <filename unknown>:0
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) <0x7f0ad7fff630 + 0x0006b> in <filename unknown>:0
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) <0x7f0ad7fff5e0 + 0x0003a> in <filename unknown>:0
at System.Runtime.CompilerServices.TaskAwaiter.GetResult () <0x7f0ad7fff5c0 + 0x00012> in <filename unknown>:0
at Discord.DiscordClient.ExecuteAndWait (System.Func`1 asyncAction) <0x41835b00 + 0x00086> in <filename unknown>:0
at MiXBot.Program.Main (System.String[] args) <0x417fbf60 + 0x002a3> in <filename unknown>:0
I have mono and .net core installed and I'm running it through mono.
Any suggestions? (I'd like to stick with discord.net if possible)
I'm just going to take a stab at the solution because I didn't see you mention that you installed dotnet core on linux. Here is a guide that has a checklist to follow your steps to make sure it's working correctly. Discord.net appears to be in .net core.
If it still fails after that, try running other .net core apps on your linux server and see if those work. I hope this helps!
https://learn.microsoft.com/en-us/dotnet/core/linux-prerequisites?tabs=netcore2x
I'm going to assume due to lack of context that you built your application using .Net Framework to which I can recommend you switch to .Net Core.
Afterwhich as mentioned by Solarcloud ensure you have Dotnet Core installed on your Linux box and then you can simply run it by dotnet MyApplication.dll after you build it, navigate to the folder etc.
as per the docs it doesn't support mono
Using this library with Mono is not supported until further notice. It is known to have issues with the library's WebSockets implementation and may crash the application upon startup.
https://docs.stillu.cc/guides/getting_started/installing.html?tabs=vs-install%2Ccore2-1
It runs perfectly fine on linux if you target .net core since d.net targets .net standard
As shown in the docs (https://docs.stillu.cc/guides/getting_started/installing.html), it's not possible to run Discord.Net with Mono.
I suggest you to switch to .NET Core. When you'll now compile the code, it will output a .dll file (and regular .exe if 3.1+)
Download .NET Core runtime on your distribution: https://learn.microsoft.com/en-us/dotnet/core/install/linux
Once it's installed you should be able to run the .dll file with the following command in the terminal:
dotnet <path_to_dll>
This problem has kind of stumpped me for the last couple of hours. Any clue why the application is crashing with this callstack in monodevelop. It will compile and run correctly if I build the application with xbuild.
Unhandled Exception:
System.Net.WebException: An exception occurred during a WebClient request. ---> System.TypeInitializationException: The type initializer for 'System.Net.WebRequest' threw an exception. ---> System.Configuration.ConfigurationErrorsException: Error Initializing the configuration system. ---> System.TypeLoadException: Failure has occurred while loading a type.
at System.Configuration.Configuration.Init (IConfigSystem system, System.String configPath, System.Configuration.Configuration parent) [0x00065] in /builddir/build/BUILD/mono-4.2.3/mcs/class/System.Configuration/System.Configuration/Configuration.cs:137
at System.Configuration.Configuration..ctor (System.Configuration.InternalConfigurationSystem system, System.String locationSubPath) [0x0005c] in /builddir/build/BUILD/mono-4.2.3/mcs/class/System.Configuration/System.Configuration/Configuration.cs:96
at System.Configuration.Configuration..ctor (System.Configuration.InternalConfigurationSystem system, System.String locationSubPath) [0x0003b] in /builddir/build/BUILD/mono-4.2.3/mcs/class/System.Configuration/System.Configuration/Configuration.cs:91
at System.Configuration.InternalConfigurationFactory.Create (System.Type typeConfigHost, System.Object[] hostInitConfigurationParams) [0x0000e] in /builddir/build/BUILD/mono-4.2.3/mcs/class/System.Configuration/System.Configuration/InternalConfigurationFactory.cs:41
at System.Configuration.ConfigurationManager.OpenExeConfigurationInternal (ConfigurationUserLevel userLevel, System.Reflection.Assembly calling_assembly, System.String exePath) [0x00102] in /builddir/build/BUILD/mono-4.2.3/mcs/class/System.Configuration/System.Configuration/ConfigurationManager.cs:119
at System.Configuration.ClientConfigurationSystem.get_Configuration () [0x00011] in /builddir/build/BUILD/mono-4.2.3/mcs/class/System.Configuration/System.Configuration/ClientConfigurationSystem.cs:49
--- End of inner exception stack trace ---
at System.Configuration.ClientConfigurationSystem.get_Configuration () [0x00025] in /builddir/build/BUILD/mono-4.2.3/mcs/class/System.Configuration/System.Configuration/ClientConfigurationSystem.cs:52
at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection (System.String configKey) [0x00000] in /builddir/build/BUILD/mono-4.2.3/mcs/class/System.Configuration/System.Configuration/ClientConfigurationSystem.cs:61
at System.Configuration.ConfigurationManager.GetSection (System.String sectionName) [0x00000] in /builddir/build/BUILD/mono-4.2.3/mcs/class/System.Configuration/System.Configuration/ConfigurationManager.cs:159
at System.Net.WebRequest..cctor () [0x00014] in /builddir/build/BUILD/mono-4.2.3/mcs/class/System/System.Net/WebRequest.cs:71
--- End of inner exception stack trace ---
at System.Net.WebClient.GetWebRequest (System.Uri address) [0x00000] in /builddir/build/BUILD/mono-4.2.3/external/referencesource/System/net/System/Net/webclient.cs:285
at ParkitectNexus.Data.Web.Client.NexusWebClient.GetWebRequest (System.Uri uri) [0x00003] in /home/michaelpollind/Desktop/ParkitectNexusClient/src/ParkitectNexus.Data/Web/Client/NexusWebClient.cs:70
at System.Net.WebClient.OpenReadAsync (System.Uri address, System.Object userToken) [0x0003b] in /builddir/build/BUILD/mono-4.2.3/external/referencesource/System/net/System/Net/webclient.cs:1846
--- End of inner exception stack trace ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /builddir/build/BUILD/mono-4.2.3/external/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00047] in /builddir/build/BUILD/mono-4.2.3/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:201
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in /builddir/build/BUILD/mono-4.2.3/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:170
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in /builddir/build/BUILD/mono-4.2.3/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:142
at System.Runtime.CompilerServices.TaskAwaiter`1[TResult].GetResult () [0x00000] in /builddir/build/BUILD/mono-4.2.3/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:372
at ParkitectNexus.Data.Web.API.ParkitectNexusAPI+<GetRequiredModIdentifiers>c__async1.MoveNext () [0x000b8] in /home/michaelpollind/Desktop/ParkitectNexusClient/src/ParkitectNexus.Data/Web/API/ParkitectNexusAPI.cs:86
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /builddir/build/BUILD/mono-4.2.3/external/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00047] in /builddir/build/BUILD/mono-4.2.3/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:201
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in /builddir/build/BUILD/mono-4.2.3/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:170
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in /builddir/build/BUILD/mono-4.2.3/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:142
at System.Runtime.CompilerServices.TaskAwaiter`1[TResult].GetResult () [0x00000] in /builddir/build/BUILD/mono-4.2.3/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:372
at ParkitectNexus.Client.Base.Pages.AssetsPageView+<GetRequiredMods>c__async0.MoveNext () [0x0007c] in /home/michaelpollind/Desktop/ParkitectNexusClient/src/ParkitectNexus.Client.Base/Pages/AssetsPageView.cs:62
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /builddir/build/BUILD/mono-4.2.3/external/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<ThrowAsync>m__1 (System.Object state) [0x00000] in /builddir/build/BUILD/mono-4.2.3/external/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:1010
at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context (System.Object state) [0x0000e] in /builddir/build/BUILD/mono-4.2.3/external/referencesource/mscorlib/system/threading/threadpool.cs:1291
at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, Boolean preserveSyncCtx) [0x00081] in /builddir/build/BUILD/mono-4.2.3/external/referencesource/mscorlib/system/threading/executioncontext.cs:581
at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, Boolean preserveSyncCtx) [0x00000] in /builddir/build/BUILD/mono-4.2.3/external/referencesource/mscorlib/system/threading/executioncontext.cs:530
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem () [0x0002a] in /builddir/build/BUILD/mono-4.2.3/external/referencesource/mscorlib/system/threading/threadpool.cs:1268
at System.Threading.ThreadPoolWorkQueue.Dispatch () [0x00096] in /builddir/build/BUILD/mono-4.2.3/external/referencesource/mscorlib/system/threading/threadpool.cs:859
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback () [0x00000] in /builddir/build/BUILD/mono-4.2.3/external/referencesource/mscorlib/system/threading/threadpool.cs:1196
After some testing I found that creating a separate project and copying everything into it seems to have resolved the configuration error. If anyone has any insight into this, I would like to know.