0

I am trying yo use caching data as per my project demands

So i coded below

   public static void Add<T>(T o, string key, double Timeout)
    {
        HttpContext.Current.Cache.Insert(
            key,
            o,
            null,
            DateTime.Now.AddHours(Timeout),
            System.Web.Caching.Cache.NoSlidingExpiration);
    }

now , i am calling a this function like

CacheHelper.Add<Employee>(new Employee() { Id = "1", name = "1"  }, "Employee", 10000);

By doing above i am getting Error:

"An unhandled exception of type 'System.NullReferenceException'"
SBI
  • 2,282
  • 1
  • 16
  • 17
Himanshu.Parkash
  • 153
  • 1
  • 3
  • 13

2 Answers2

0

You need to debug your application. Something is null and you need to find out what.

My personal guess goes to HttpContext.Current being null.

nvoigt
  • 68,786
  • 25
  • 88
  • 134
0

You may use this code only in Http request pipeline procees. Otherwise HttpContext.Current will be null.

Dmytro Rudenko
  • 2,504
  • 2
  • 12
  • 22