Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

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


View products that this article applies to.

This article was previously published under Q311388

↑ Back to the top


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.

↑ Back to the top


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.

↑ Back to the top


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).

↑ Back to the top


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:

↑ Back to the top


Keywords: KB311388, kbstate, kbprb, kbcaching

↑ Back to the top

Article Info
Article ID : 311388
Revision : 9
Created on : 5/11/2007
Published on : 5/11/2007
Exists online : False
Views : 490