PRB: System.ArgumentOutOfRangeException Occurs When slidingExpiration Parameter Exceeds One Year (311388)



The information in this article applies to:

  • Microsoft ASP.NET (included with the .NET Framework 1.1)
  • Microsoft ASP.NET (included with the .NET Framework) 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("MyCache", ValuetoCache, Nothing, DateTime.MaxValue, New TimeSpan(366, 0, 0, 0))
				

-or-

[Visual C# .NET]

Cache.Insert("MyCache", 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).

REFERENCES

For additional information, click the article number below to view the article in the Microsoft Knowledge Base:

307225 INFO: ASP.NET Caching Overview

For more information on data caching in ASP.NET, refer to the following Microsoft Web sites: For more information about the Cache class and its related methods, refer to the following topics in the Microsoft .NET Framework Class Library:

Modification Type:MinorLast Reviewed:7/8/2003
Keywords:kbCaching kbprb kbState KB311388