Skip to content

ArgumentOutOfRangeException is also thrown when setting HttpClient.Timeout to more than 24 days #10962

@datvm

Description

@datvm

Type of issue

Missing information

Description

ArgumentOutOfRangeException
The timeout specified is less than or equal to zero and is not InfiniteTimeSpan.

From the source code, it actually throws when you put in value greater than about 24 days (int.MaxValuems) too:

private static readonly TimeSpan s_maxTimeout = TimeSpan.FromMilliseconds(int.MaxValue);
// ...
        public TimeSpan Timeout
        {
            get => _timeout;
            set
            {
                if (value != s_infiniteTimeout)
                {
                    ArgumentOutOfRangeException.ThrowIfLessThanOrEqual(value, TimeSpan.Zero);
                    ArgumentOutOfRangeException.ThrowIfGreaterThan(value, s_maxTimeout);
                }
                CheckDisposedOrStarted();
                _timeout = value;
            }
        }

I encountered this issue when trying to set it to TimeSpan.MaxValue:

System.ArgumentOutOfRangeException: value ('10675199.02:48:05.4775807') must be less than or equal to '24.20:31:23.6470000'. (Parameter 'value')

Page URL

https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpclient.timeout?view=net-9.0

Content source URL

https://github.com/dotnet/dotnet-api-docs/blob/main/xml/System.Net.Http/HttpClient.xml

Document Version Independent Id

199a48e3-16ed-9fe0-8957-f14f37a17acd

Article author

@karelz

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions