.NET Framework 4.7 breaking WebForms Page Cache insert RRS feed

  • Question

  • In an ASP.NET webforms context (FYI - .NET Framework 4.5.1 project), the following code works when .NET Framework 4.7 is not installed. But when Framework 4.7 is installed (which came out today), I get a NullReference exception.

    public class Default : System.Web.UI.Page
      protected override void OnInit(EventArgs e) {
          string key = "key", data = "data";
          Cache.Insert(key, data, null, DateTime.Now.AddMinutes(5), TimeSpan.Zero);
          Cache[key].ToString(); // Throws NRE when 4.7 installed

    After debugging I've determined the item is being added to the cache and then immediately deleted. I found two workarounds:

    1. Web.config

           <cache disableExpiration="true"/>

    2. Change insert statement to this

    Cache.Insert(key, data, null, DateTime.Now.AddMinutes(5),
       TimeSpan.Zero, CacheItemPriority.Normal, 
       (key,value,removal)=> { });

    I'm very confused as to what I'm doing wrong in my first cache statement that works fine before installing v4.7. Is this a bug?


    Fungus Man

    Friday, June 16, 2017 12:13 AM

All replies