Completed
Last Updated: 29 Sep 2025 14:22 by ADMIN
Release 2025.2.520 (2025 Q2)
Flemming
Created on: 04 Mar 2025 08:03
Category: SpreadProcessing
Type: Bug Report
3
SpreadProcessing: ArgumentOutOfRangeException: 'Specified argument was out of the range of valid values. (Parameter 'delay') when using timeout with Timespan.MaxValue
This is a sample code to replicate the error which is triggered on export: 
            string inputFileName = "input.xlsx";
            if (!File.Exists(inputFileName))
            {
                throw new FileNotFoundException(String.Format("File {0} was not found!", inputFileName));
            }

            Telerik.Windows.Documents.Spreadsheet.Model.Workbook workbook;
            IWorkbookFormatProvider formatProvider = new Telerik.Windows.Documents.Spreadsheet.FormatProviders.OpenXml.Xlsx.XlsxFormatProvider();

            using (Stream input = new FileStream(inputFileName, FileMode.Open))
            { 
                workbook = formatProvider.Import(input, TimeSpan.MaxValue);
            }
            string outputFilePath = "output.xlsx";

            using (Stream output = new FileStream(outputFilePath, FileMode.Create))
            {
                formatProvider.Export(workbook, output, TimeSpan.MaxValue);
            }
            Process.Start(new ProcessStartInfo() { FileName = outputFilePath, UseShellExecute = true });
4 comments
ADMIN
Dess | Tech Support Engineer, Principal
Posted on: 29 Sep 2025 14:22

Hi,

I would like to follow up with additional information about the existing behavior of our timeout mechanism and how it will be changed in the next version.

Our CancelationTokenSourceFactory internlly uses the CancelAfter(TimeSpan delay) method. It is expected to throw an ArgumentOutOfRangeException when delay.TotalMilliseconds is less than -1 or greater than Int32.MaxValue (or UInt32.MaxValue - 1 on some versions of .NET). Note that this upper bound is more restrictive than TimeSpan.MaxValue:
https://learn.microsoft.com/en-us/dotnet/api/system.threading.cancellationtokensource.cancelafter?view=net-9.0#system-threading-cancellationtokensource-cancelafter%28system-timespan%29 

Now, the timeout mechanism will use Timeout.InfiniteTimeSpan as an upper boundary. InfiniteTimeSpan is a constant used to specify an infinite waiting period, for methods that accept a TimeSpan parameter: https://learn.microsoft.com/en-us/dotnet/api/system.threading.timeout.infinitetimespan?view=net-9.0 

Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik

Your perspective matters! Join other professionals in the State of Designer-Developer Collaboration 2025: Workflows, Trends and AI survey to share how AI and new workflows are impacting collaboration, and be among the first to see the key findings.
Start the 2025 Survey
ADMIN
Dess | Tech Support Engineer, Principal
Posted on: 17 Jun 2025 07:19

Hello, Flemming and Piet,

The TimeSpan interval is up to the developer and should be considered with the environment-specific configurations. In case of developing a web application for example, set such a timeout interval value that would be safe enough to protect the application from potential DDoS attacks. If the application is expected to be delivered directly to the end-users, it is possible to use TimeSpan=null as well.

Piet opened a separate public item for improving how the TimeSpan ranges are handled. You can cast your vote for the item, track its progress, subscribe for status changes, and add your comments on the following link:

CancelationTokenSourceFactory.CreateTokenSource(TimeSpan? timeSpan) does not do proper argument checking

I hope this information helps.

Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Flemming
Posted on: 12 Jun 2025 09:50

It may come down to .NET design; but FormatProvidor is (I assume) Telerik code, and since you are defining a TimeSpan argument to the method;, IMHO you should also take care of any value passed.

I don't expect an exception on a valid argument not found by the compiler.

Anyway, it is not a showstopper, just nuisance ....

Piet
Posted on: 11 Jun 2025 14:00

this is normal .NET cancellation behavior, the maximum timeout is int.MaxValue or (uint.MaxValue-1) milliseconds (see here), which is many orders of magnitude smaller than TimeSpan.MaxValue.

If you do not want a timeout, which seems to be the intention here, you should pass Timeout.InfiniteTimespan instead of TimeSpan.MaxValue.