Search code examples
wcfaoppostsharp

PostSharp - OnMethodBoundaryAspect in OperationContract


I am using PostSharp - OnMethodBoundaryAspect in OperationContract. The aspect doesnt seem to fire though. I have the necessary reference to postsharp dll. Pseudo code below.

  • Aspect

    [Serializable]
    [MulticastAttributeUsage(MulticastTargets.Method, Inheritance =  MulticastInheritance.Multicast)]
    public class LoggingAspect : OnMethodBoundaryAspect
    {
      //Implementation for entry and exit
    }
    
  • Usage

    [ServiceContract]
    public interface ITest
    {
     [OperationContract]
     [LoggingAspect(.....)]
      void Test();
    }
    

Any help is deeply appreciated


Solution

  • We need to do the following

    1. Install Postsharp through NuGet on the project which you want to write your custom aspect.
    2. This will ensure that the targets are present in the .csproj files thereby enabling injection during compile time.
    3. Install PostSharp though NuGet in all projects where you want to use the aspect which you wrote as mentioned in #1

    Thanks AlexD and Daniel Balas for the inputs