Last post Oct 15, 2018 10:50 AM by email@example.com
Oct 10, 2018 10:02 AMfirstname.lastname@example.org|LINK
i wanna add some data into cache so, i used below code. its working perfectly from development computer when i publish into server then its throwing exception "Object reference not set to an instance of an object. Inner Exception is ", using log i found
the place of issue, its at exactly if (cache["Key1"] == null)
System.Web.Caching.Cache cache = new System.Web.Caching.Cache();
if (cache["Key1"] == null)
cache.Add("Key1", "Value 1", null, DateTime.Now.AddSeconds(60), System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.Normal, null);
the reason why im using System.Web.Caching.Cache is, i have another vb.net project, its like Public Shared Function GetContentString(ByRef cache As Cache) there its expecting object of System.Web.Caching.Cache
really i dont know the reason of why its not working only from server? do i need to change anything in IIS? experts can you please help me!!
Oct 10, 2018 11:31 AM|mgebhard|LINK
This could be a design bug but you have not explained the design clearly and there's no source code. There's no way to provide accurate assistance.
Can you explain the design? Are you trying to pass data between applications hosted on IIS?
Oct 11, 2018 07:00 AM|Fei Han - MSFT|LINK
its throwing exception "Object reference not set to an instance of an object.
I suspect that in elsewhere you get cache["Key1"] with null and convert it to other type or assign it to another variable etc, which might cause the issue.
Besides, if you'd like to share data between multiple applications built with different languages (or platform), you can use Redis Cache etc. Or store the data in a temporary table in your database.
Oct 15, 2018 10:50 AMemail@example.com|LINK
its resolved using System.Web.Caching.Cache cache = HttpRuntime.Cache;