MemoryCache gets disposed after PollingInterval when used in WebApp in Integrated Pipeline mode - by scubadam

Status : 

  Deferred<br /><br />
		The product team has reviewed this issue and has deferred it for consideration at a later time.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.

Sign in
to vote
ID 764911 Comments
Status Closed Workarounds
Type Bug Repros 12
Opened 9/27/2012 3:22:40 AM
Access Restriction Public


When using either the MemoryCache.Default or my own MemoryCache after the PollingInterval (default of 2 minutes) the cache is in the disposed state (_disposed=1 ) on examination in the debugger. Setting the PollingInterval longer or shorter means the cache works for more or less time. In its disposed state the cache basically functions as if it is constantly empty hence no cache.
Before the PollingInterval however the cache works as expected.

This only seems to manifest itself when using Integrated Managed Pipeline Mode in IIS7. When on IIS6 or running in Classic mode under IIS7 I did not experience this issue and I found this due to a degradation in performance going from old server to a new server.

A number of people seem to have noticed this but I don't see a bug for this issue here.
Sign in to post a comment.
Posted by scubadam on 5/18/2015 at 5:14 AM
Just to note Scott's workaround has worked for myself and I have had that in production for some time on some older code bases where upgrade to .net 4.5 has not proved possible. Sorry I forgot to thank you Scott.
Posted by teljj001 on 5/17/2015 at 6:48 PM
The quick fix does not appear to be available. How can I access it? Upgrading to 4.5 is not an option for all our customers, particularly those who install our product on server resources that are shared with other products.
Posted by johval on 8/16/2013 at 12:21 AM
We are also experiencing this problem. Apparently the quick fix is still not available?
Posted by Stimo on 5/28/2013 at 4:15 AM
Scott, thanks for the update. Any news on the quick fix (#578315)? It's still not available for download.

Posted by Scott Hanselman on 3/30/2013 at 12:10 AM
So, here's some news. We looked into this and YES, this is a bug in .NET 4.

The good news is that it was fixed in .NET 4.5, so if you can, update your installation to .NET 4.5 and you're solid.

The other good news it that this fix has been back-ported to .NET 4 and will be available as a QFE (Quick Fix...a one off fix you'll apply) #578315. It was backported/fixed and it should be out ASAP. I'll try to get an exact date, but it's soon.

The other other good news is that there's a workaround for this on .NET 4 before the QFE. The workaround is weird, but it could unblock you.
using (ExecutionContext.SuppressFlow()) {
// Create memory cache instance under disabled execution context flow            
return new YourCacheThing.GeneralMemoryCache(…);

Hope this helps.
Posted by fuzzyGURU on 3/13/2013 at 8:47 AM
Adding this to the web.config helps to some degree:

         <add name="Default"
             pollingInterval="00:02:00" />

However, I have noticed that once the pollingInterval has been hit, the ObjectCache becomes useless. This means that I need to set the pollingInterval to a high value, and then ensure that the AppPool recycles before that so it is always reset first before it dies.
Posted by scubadam on 2/20/2013 at 7:50 AM
Is there any update on this? Is there a permission needed by the pool Identity service account that would allow this to work. Alternatively does .Net 4.5 fix this?
Posted by bcathey on 11/12/2012 at 1:55 PM
Same here. on IIS7; Integrated Mode; .Net 4.0.30319.
I thought ASP.Net MVC on IIS7 would be a well-tested scenario for this since it supposedly replaces ASP.Net caching. I started to worry when I couldn't Get() from cache across processes in tests. I will probably look at NCache ( if this isn't resolved in the very short term.
Posted by CC_VICTOR_VIANA on 11/8/2012 at 4:30 AM
Good morning!
I'm having the same problem only in IIS 8,
I assign an object in the cache and then immediately try to retrieve and recover when I see what is null.

Has anyone got a solution to this problem Cache?
Posted by scubadam on 10/23/2012 at 2:01 AM
Ok I created a simple reproducer (I attached the file but cannot see it...)
On doing this I noticed some more requirements to see this issue. You have to be using an AppPool running as a specific username, in this case my own user but equally a service account on servers. And the site has to be run with Windows Auth required.

In this instance a simple reproducer shows the exact behavior myself and others have seen.
Hopefully this should be enough for you to advise what is going wrong and what I should do.
Posted by scubadam on 10/23/2012 at 1:07 AM
I also found that this wasn't an issue on a WCF webservice and the Website where this is an issue is a Webforms aspx website. I haven't tried it on an MVC project.
Posted by scubadam on 10/8/2012 at 6:54 AM
I found the specific Framework version according to the App pool in IIS 4.0.30319
Posted by scubadam on 10/4/2012 at 1:26 AM
.Net v4 as specified in the details is the one used by the application pool and the target version of the web app. Is there a more specific version number you are after and how do I find it.
Posted by Microsoft on 10/3/2012 at 3:54 PM
Can you please indicate what version of ASP.NET you are experiencing the issue on?
Posted by Microsoft on 9/27/2012 at 11:33 PM
Thanks for your feedback. Your issue has been routed to the appropriate VS development team for investigation. We will contact you if we require any additional information.
Posted by Microsoft on 9/27/2012 at 3:50 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(