question

Stesvis-5434 avatar image
0 Votes"
Stesvis-5434 asked LeonLu-MSFT commented

Help with lots of HttpClient errors

Lately I've been seeing tons of HttpClient exceptions in my AppCenter diagnostic reports, examples are:

System.Net.WebException

ModernHttpClient.NativeMessageHandler.SendAsync (System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) <0x105255f90 + 0x01143> in <67401bece23c4316a0cb1acd7b396157#792a49c16f2dfe546fe4e57621a98e65>:0
System.Net.WebException: Error Domain=NSURLErrorDomain Code=-1001 "The request timed out."


System.Threading.Tasks.TaskCanceledException


NativeMessageHandler.SendAsync (System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken)
System.Threading.Tasks.TaskCanceledException: A task was canceled.

Now, while I understand that some users are in remote locations, maybe is there something wrong with ModernHttpClient?
Should I stop using it?

In my app, I defined it like this in App.xaml.cs:

private static HttpClient _myHttpClient;
        public static HttpClient MyHttpClient
        {
            get
            {
                if (_myHttpClient == null)
                {
                    _myHttpClient = new HttpClient(new NativeMessageHandler(false, new TLSConfig()))
                    {
                        Timeout = TimeSpan.FromSeconds(45),
                        BaseAddress = new Uri(Misc.Constants.ApiUrlsBase.BaseUrl),
                    };

                    _myHttpClient.DefaultRequestHeaders.Add(CustomRequestHeaders.ApiVersion, "2");
                }

                return _myHttpClient;
            }
        }


Can someone suggest a reason why I see so MANY errors like these? Anything obvious that I am missing?

Could this setting be an issue?
136409-image.png


dotnet-xamarinforms
image.png (2.7 KiB)
· 5
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Above exception is related to Network conntection between Client to Server.

Please advice you users to open your application's settings, If your application have selected WLAN & Cellular Data like following screenshot.

136641-image.png


0 Votes 0 ·
image.png (37.2 KiB)

@LeonLu-MSFT yes they all have WiFi and Data always enabled. In fact most of the time everything works, but then a few times a day they throw these exceptions, and if you multiply by the number of users, I get lots.

I wonder if ModernHttpClient could be an extra problem. Should I remove it and use the native HttpClient?

0 Votes 0 ·

It is caused by the network connection, Users' connection not stable.

0 Votes 0 ·
Show more comments

0 Answers