MemoryCache Empty : Returns null after being set

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 just days ago 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.

UPDATE: The Hotfix is http://support.microsoft.com/kb/2828843 and you can request it here: https://support.microsoft.com/contactus/emailcontact.aspx?scid=sw;%5BLN%5D;1422

Leave a Comment