'System.Net.Http.HttpRequestException: No such host is known Occuring regularly on Xamarin.Android

I've witnessed something strange in an app I published for production. The app is written in Xamarin Android, and I have added permissions in the manifest for internet. But, I keep getting the exception below on error logs on appcenter. I check in the app has an internet connection using XamarinEssentials. And in the error logs I send to appcenter, I add a flag telling me if the user had internet when the error occured. And the flag is always true. This happens only on android, and not on iOS.

Here are my permissions.

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

I increased the timeout of my HttpClients to 10mins too. But this issue still occures.

I can't figure out what is wrong. Can someone help please?

"Exception": { "ClassName": "System.Net.Http.HttpRequestException", "Message": "No such host is known", "Data": null, "InnerException": { "NativeErrorCode": 11001, "ClassName": "System.Net.Sockets.SocketException", "Message": "No such host is known", "Data": null, "InnerException": null, "HelpURL": null, "StackTraceString": " at System.Net.Http.ConnectHelper.ConnectAsync (System.String host, System.Int32 port, System.Threading.CancellationToken cancellationToken) [0x00110] in <494a9f6836c245e2b2dd60e5456f6e8f>:0 ", "RemoteStackTraceString": null, "RemoteStackIndex": 0, "ExceptionMethod": null, "HResult": -2147467259, "Source": "mscorlib" }, "HelpURL": null, "StackTraceString": " at System.Net.Http.ConnectHelper.ConnectAsync (System.String host, System.Int32 port, System.Threading.CancellationToken cancellationToken) [0x001ac] in <494a9f6836c245e2b2dd60e5456f6e8f>:0 \n at System.Net.Http.HttpConnectionPool.CreateConnectionAsync (System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) [0x00134] in <494a9f6836c245e2b2dd60e5456f6e8f>:0 \n at System.Net.Http.HttpConnectionPool.WaitForCreatedConnectionAsync (System.Threading.Tasks.ValueTask1[TResult] creationTask) [0x000a2] in <494a9f6836c245e2b2dd60e5456f6e8f>:0 \n at System.Net.Http.HttpConnectionPool.SendWithRetryAsync (System.Net.Http.HttpRequestMessage request, System.Boolean doRequestAuth, System.Threading.CancellationToken cancellationToken) [0x00089] in <494a9f6836c245e2b2dd60e5456f6e8f>:0 \n at System.Net.Http.RedirectHandler.SendAsync (System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) [0x000ba] in <494a9f6836c245e2b2dd60e5456f6e8f>:0 \n at Microsoft.Extensions.Http.Logging.LoggingHttpMessageHandler.SendAsync (System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) [0x000d7] in <dae2b93d460143a69fe93cb50ed6a7ed>:0 \n at Microsoft.Extensions.Http.Logging.LoggingScopeHttpMessageHandler.SendAsync (System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) [0x000ef] in <dae2b93d460143a69fe93cb50ed6a7ed>:0 \n at System.Net.Http.HttpClient.FinishSendAsyncBuffered (System.Threading.Tasks.Task1[TResult] sendTask, System.Net.Http.HttpRequestMessage request, System.Threading.CancellationTokenSource cts, System.Boolean disposeCts) [0x0017e] in <494a9f6836c245e2b2dd60e5456f6e8f>:0 \n at MobileApp.ApiServices.Implementations.Base.BaseService.Get[T] (System.String url) [0x00092] in <3c1e10a5d5bb494c8065e3ec7ba595b1>:0 \n at MobileApp.ApiServices.Implementations.ProductService.GetProduct (System.Int32 id) [0x0011d] in <3c1e10a5d5bb494c8065e3ec7ba595b1>:0 \n at MobileApp.ViewModels.ProductViewModel.InitializeProduct () [0x00106] in <4bea1fef8e7b499c96f39a82864ce3fe>:0 \n at MobileApp.ViewModels.ProductViewModel.Initialize () [0x001a0] in <4bea1fef8e7b499c96f39a82864ce3fe>:0 ", "RemoteStackTraceString": null, "RemoteStackIndex": 0, "ExceptionMethod": null, "HResult": -2147467259, "Source": "mscorlib" },System.Net.Http.HttpRequestException: No such host is known ---> System.Net.Sockets.SocketException: No such host is known at System.Net.Http.ConnectHelper.ConnectAsync (System.String host, System.Int32 port, System.Threading.CancellationToken cancellationToken) [0x00110] in <494a9f6836c245e2b2dd60e5456f6e8f>:0 --- End of inner exception stack trace --- at System.Net.Http.ConnectHelper.ConnectAsync (System.String host, System.Int32 port, System.Threading.CancellationToken cancellationToken) [0x001ac] in <494a9f6836c245e2b2dd60e5456f6e8f>:0 at System.Net.Http.HttpConnectionPool.Creat



Solution 1:[1]

I began to run into the same issue yesterday after I updated Xamarin.Android. In my case I had a VPN running and when I shut it off everything worked fine again. I'm not sure what changed because I was able to work with my VPN just fine before yesterday. I hope that helps.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 William Smith