'CachingServices' does not contain a definition for 'CurrentContext' error while compiling with PostSharp 5.0.48

henry.nordstrom's Avatar


26 Mar, 2018 07:19 AM

I upgraded from a previous 5.0.* version to 5.0.48, and now one of my applications fails to compile.

The error message is:
Error CS0117 'CachingServices' does not contain a definition for 'CurrentContext'


        public static IEnumerable<AclToken> GetAllModuleAccessTokensForGroup(Guid groupguid)

In this piece of code, Visual Studio shows CurrentContext as red.

  1. 1 Posted by henry.nordstrom on 26 Mar, 2018 10:15 AM

    henry.nordstrom's Avatar

    Reverting to PostSharp 5.0.46 seemed to resolve the issue.
    Unfortunately I had to downgrade a whole bunch of projects, as they all depend on a couple of projects that also use PostSharp.

    Your sample code from https://www.postsharp.net/caching still uses a syntax that seems to be incompatible with 5.0.48:
        public static Account GetAccount(int id)
          // Add an object-oriented dependency to GetMethod.
          CachingServices.CurrentContext.AddDependency(new AccountDependency(id));
          return DetailsSkipped();

  2. 2 Posted by henry.nordstrom on 26 Mar, 2018 03:11 PM

    henry.nordstrom's Avatar

    Also it seems that [PSerializable] is only recognized until PostSharp 5.0.45

  3. Support Staff 3 Posted by PostSharp Techn... on 29 Mar, 2018 01:56 PM

    PostSharp Technologies's Avatar


    thanks for reporting the issue.

    we have added back CachingServices.CurrentContext as obsolete declaration in PostSharp 5.0.49. The proper way is to use CachingContext.Current instead. The original one was removed by mistake.

    Could you please explain the problem with [PSerializable] in more details?

    Best regards,

  4. 4 Posted by henry.nordstrom on 30 Mar, 2018 10:25 AM

    henry.nordstrom's Avatar

    The [PSerializable] problem is similar to the CachingServices problem => the compiler does not recognize it if with versions higher than 5.0.45.
    I verified this by downgrading from 5.0.48 => 5.0.46 => 5.0.45 ... it started working again at 5.0.45.

    I like your product, but I would appreciate it if the documentation would be kept up to date. Also it would be nice to get better information on breaking changes.

  5. Support Staff 5 Posted by PostSharp Techn... on 03 Apr, 2018 02:48 PM

    PostSharp Technologies's Avatar


    We were not able to reproduce the issue with [PSerializable] yet. Could you please send us a sample projects that demonstrates the issue?


  6. Support Staff 6 Posted by PostSharp Techn... on 11 Apr, 2018 04:28 PM

    PostSharp Technologies's Avatar


    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.

    PostSharp Team

  7. PostSharp Technologies closed this discussion on 11 Apr, 2018 04:28 PM.

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

Keyboard shortcuts


? 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