Search code examples
multithreadingthread-safetyaoppostsharp

PostSharp OnMethodBoundaryAspect Not Thread Safe


I'm trying out PostSharp AOP and am surprised that OnMethodBoundaryAspect is not thread safe.

The same instance of the aspect is shared between method calls.

This makes its utility quite limited in number of use cases where it can be applied.

Any way to address this?


Solution

  • All OnEntry, OnExit and OnException methods receive a parameter of the type MethodExecutionArgs. This parameter has a property called MethodExecutionTag, and this one can be used for sharing information between these events.

    http://doc.sharpcrafters.com/postsharp-2.1/Default.aspx##PostSharp-2.1.chm/html/P_PostSharp_Aspects_MethodExecutionArgs_MethodExecutionTag.htm

    The third question on link http://www.sharpcrafters.com/blog/post/Stay-DRY-Webinar.aspx is similar as yours.