Here's my bit of code:
List<Sale> sales = new List<Sale>();
if (Cache["Sales"] != null)
{
sales = (List<Sale>)Cache["Sales"];
}
else
{
...
Cache.Add("Sales", sales, null, DateTime.Now.AddMinutes(20),
Cache.NoSlidingExpiration, CacheItemPriority.Normal, null);
}
When I try to pull the data from the cache, my "sales" object is null. Wondering why that code is hit at all, I ran the debugger in VS to see what was in the Cache object.
The Cache contains the data I need, but when it gets the data from cache, "sales" still comes out as null.
Is there something I'm doing wrong here?
EDIT:
I'm getting this error on casting:
[A]System.Collections.Generic.List
1[controls_mySales+Sale] cannot be cast to [B]System.Collections.Generic.List
1[controls_mySales+Sale]. Type A originates from 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' in the context 'LoadNeither' at location 'C:\WINDOWS\assembly\GAC_32\mscorlib\2.0.0.0__b77a5c561934e089\mscorlib.dll'. Type B originates from 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' in the context 'LoadNeither' at location 'C:\WINDOWS\assembly\GAC_32\mscorlib\2.0.0.0__b77a5c561934e089\mscorlib.dll'