Microsoft KB Archive/311388

= PRB: System.ArgumentOutOfRangeException Occurs When slidingExpiration Parameter Exceeds One Year =

Article ID: 311388

Article Last Modified on 5/11/2007

-

APPLIES TO


 * Microsoft ASP.NET 1.1
 * Microsoft ASP.NET 1.0

-



This article was previously published under Q311388



SYMPTOMS
When you use either the Insert method or the Add method of the Cache class in ASP.NET to perform data caching, you may receive the following error message about the value of the slidingExpiration parameter:

Specified argument was out of the range of valid values. Parameter name: slidingExpiration

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.



CAUSE
This error occurs because the slidingExpiration input parameter is less than TimeSpan.Zero or greater than one year when you call either the Cache.Insert method or the Cache.Add method. This range is set within the Cache class itself. If the TimeSpan object's value for the associated slidingExpiration parameter is not within this range, ASP.NET throws an exception of type ArgumentOutOfRangeException.



MORE INFORMATION
To reproduce this problem, use the Insert method as follows: [Visual Basic .NET]

Cache.Insert(&quot;MyCache&quot;, ValuetoCache, Nothing, DateTime.MaxValue, New TimeSpan(366, 0, 0, 0))

-or-

[Visual C# .NET]

Cache.Insert(&quot;MyCache&quot;, ValueToCache, null, DateTime.MaxValue, new TimeSpan(366,0,0,0)); In the preceding code, the Days input parameter of the constructor for the TimeSpan class is set to 366, which is greater than one year (365 days).

