locked
Memory Cache is getting the exception Attempted to divide by zero System.Runtime.Caching.MemoryCacheStatistics.SetTrimStats RRS feed

  • Question

  • User-1119641991 posted

    I am using Memory Cache to store objects in the memory, I am using asp.net web-api (Framework - 4.6.1). Sometimes it's throwing the exception - Attempted to divide by zero. StackTrace: at System.Runtime.Caching.MemoryCacheStatistics.SetTrimStats and crashing the app pool

    Is it because of memory pressure? As per my understanding it tries to evict the cache when there is a memory crunch. MemoryCacheStatistics instance gets set up on creation of the cache. This type sets up a timer (based upon the polling) to automatically trim the cache. Somehow the _totalcCountBeforeTrim is 0 because of the memory issue.

    If my understanding is correct then how can IIS be prevented from crashing?

    Tuesday, February 12, 2019 10:25 AM

All replies

  • User839733648 posted

    Hi samrecd,

    According to your description, I have some confusion.

    I am using Memory Cache to store objects in the memory, I am using asp.net web-api (Framework - 4.6.1).

    How do you use Memory Cache? Could you share the related codes?

    Sometimes it's throwing the exception - Attempted to divide by zero. StackTrace: at System.Runtime.Caching.MemoryCacheStatistics.SetTrimStats and crashing the app pool

    You say sometimes, could you describe in detail that in which condition does the exception happen?

    And could you share the detailed StackTrace information so that it may be easier for us to help you?

    Best Regards,

    Jenifer

    Wednesday, February 13, 2019 6:33 AM