system.net.http.httpclient does not respect timespan above 100 seconds (.Net standard 2.0.2)

Andreas Østergaard Madsen 0 Reputation points
2023-07-11T08:50:36.7766667+00:00

Hey

We have encountered a problem where the HTTP client provided by system.net does not respect any timeout giving above 100 seconds on a iOS tablet application written in .Net / Xamarin

It is defined as below:

HttpClient HttpClientLongTimeout = new HttpClient(HttpClientHandler);
            HttpClientLongTimeout.Timeout = TimeSpan.FromMinutes(10);

And then called on by

var response = await HttpClientLongTimeout.GetAsync(url).ConfigureAwait(false);

As long as the value is over 100 seconds then it does not seem to care and simply fails with a timeout exception that leads to a task was cancelled exception.

We have tried to add the following as a workaround, but it did not have any effect either.

 NSUrlSessionConfiguration.DefaultSessionConfiguration.TimeoutIntervalForRequest = 30000.0;
            NSUrlSessionConfiguration.DefaultSessionConfiguration.TimeoutIntervalForResource = 30000.0;

It seems from debugging that the timeout value for the request is reset to default 100 seconds at a system level.

Can you offer any advice to how we can get around this?

.NET
.NET
Microsoft Technologies based on the .NET software framework.
4,090 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,277 questions
Not Monitored
Not Monitored
Tag not monitored by Microsoft.
41,886 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.