Caching Randomly throws InvalidOperationException

gregf's Avatar

gregf

12 Jun, 2018 01:54 PM

We are currently using PostSharp Caching throughout our program recently we've noticed randomly an InvalidOperationException is occurring during the caching process. The error message reads "Cannot add a dependency to a context that has already been closed." This does not appear to be a Windows generated error message but I also can't find it in the Postsharp knowledge base either but every time it occurs it throws from the Postsharp library. I was hoping someone in support could give some insight into this and why it might be occurring, as I'm kind of poking around in the dark with this at the moment and can't make much sense of it.

Call stack example:

 at PostSharp.Patterns.Caching.CachingContext.AddDependency (PostSharp.Patterns.Caching, Version=5.0.37.0, Culture=neutral, PublicKeyToken=e7f631e6ce13f078) 
at PostSharp.Patterns.Caching.CachingContext.AddDependency (PostSharp.Patterns.Caching, Version=5.0.37.0, Culture=neutral, PublicKeyToken=e7f631e6ce13f078) 
at PostSharp.Patterns.Caching.Implementation.CachingFrontend.AddCacheHitDependencies (PostSharp.Patterns.Caching, Version=5.0.37.0, Culture=neutral, PublicKeyToken=e7f631e6ce13f078) 
at PostSharp.Patterns.Caching.Implementation.CachingFrontend.GetOrAdd (PostSharp.Patterns.Caching, Version=5.0.37.0, Culture=neutral, PublicKeyToken=e7f631e6ce13f078) 
at PostSharp.Patterns.Caching.CacheAttribute.OnInvoke (PostSharp.Patterns.Caching, Version=5.0.37.0, Culture=neutral, PublicKeyToken=e7f631e6ce13f078) 
at ABELSoft.Dental.Application.Managers.ProviderManager.GetProviderName
  1. Support Staff 1 Posted by PostSharp Techn... on 12 Jun, 2018 02:51 PM

    PostSharp Technologies's Avatar

    Hi Greg,

    Thank you for trying caching.

    The exception is an internal one; most probably you're doing nothing wrong and this is a bug.
    It seems it happens when a cached method is invoking another cache method, which is a supported scenario, but somehow some untested condition is happening there.

    Is it possible that GetProviderName is (directly or indirectly) invoked from a cached async method? That would explain the randomness of the issue. Please confirm this hypothesis.

    Another way to move forward is to enable logging of caching. Install the PostSharp.Patterns.Diagnostics package (plus one relevant back-end package) and enable logging using this code:

    LoggingServices.DefaultBackend = new ConsoleLoggingBackend(); // Replace with the relevant backend
    LoggingServices.DefaultBackend.GetSource(LoggingRoles.Caching).SetLevel(LogLevel.Debug);
    ````
    
    See http://doc.postsharp.net/add-logging#s2 for details about configuring logging (remember that you need to configure the `Caching` role, not the default one).
    
    Then you can send us the log.
    
    Thanks.
    
    -gael
    
  2. Support Staff 2 Posted by PostSharp Techn... on 27 Jun, 2018 04:11 PM

    PostSharp Technologies's Avatar

    Hello,

    We are going to close this request as there have not been any further updates. Please feel free to reopen the discussion if you need more help.

    Thanks,
    PostSharp Team

  3. PostSharp Technologies closed this discussion on 27 Jun, 2018 04:11 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac