0

I have a problem with PostSharp, which in short can be described as "some aspects don't fire and are not shown in PostSharp Explorer".

enter image description here

As could be seen on a screenshot two aspects from Authorization namespace, which are inherited from MethodInterceptorAspect are presented in PostSharp explorer and two new aspects from ExceptionHandling namespace which are derived from OnExceptionAspect are not.

Below is a code of one of them: a 'standard' aspect made by manual, almost the same as working aspets except it derives from another base class. I tried to identify the problem commenting different parts of code but it didn't help.

[Serializable]
[AttributeUsage(AttributeTargets.All)]
public class HandleExceptionAttribute : OnExceptionAspect
{
    /// <summary>
    /// Method executed <b>after</b> the body of methods to which this aspect is applied,
    ///               in case that the method resulted with an exception (i.e., in a <c>catch</c> block).
    /// </summary>
    /// <param name="args">Advice arguments.</param>
    public override void OnException(MethodExecutionArgs args)
    {
        // some exception handling code
    }
}

Moreover I just added a simple aspect right from the sample and it also not shown in PostSharp Explorer.

Question

So the question is: why aspects don't compile and fire?

Nozim Turakulov
  • 869
  • 1
  • 9
  • 19
  • 1
    PostSharp explorer doesn't show any aspects that are not applied to any target (for example a method). What does it mean "aspects don't compile and fire"? Are there any build warnings or errors? Does it mean that you have a method decorated with HandleExceptionAttribute and when the method throws an exception then a breakpoint inside the OnException method is not hit? – Jakub Linhart May 19 '16 at 09:43
  • @JakubLinhart Yes, you're right. Aspects are applied to methods and classes, but not shown in Postsharp Explorer and breakpoints in key methods don't break debugging. I didn't know that without usage aspects not shown in explorer (moreover in my case they were applied), so I thought they ware not weaved into IL code. That's what I ment under "don't compile". – Nozim Turakulov May 19 '16 at 12:06

1 Answers1

0

Unswering my own question / Question is updated

It seems it's a bug of PostSharp or maybe a conflict between PostSharp, ReSharper and Visual Studio.

After appling one of new aspects on abstract method (previously aspect was appliet at class level) I've got a build error about 'incompatibilty'. Then I made abstract method virtual and project compiled succesfully. And Resharper Explorer shown both new aspects with all their affects. To make it clear I made 'undo changes' and wanted to repeat my actions, but this time all aspects dissappeared from PostSharp Explorer like they are not applied at all (while they where still applied totally about 300 times) and ReSharper highlighted all aspects usages as uknown types.

After suspending ReSharper, clearing the solution, restarting the VisualStudio and rebuilding solution, three aspect appeared in PostSharp explorer and the forth one appeared after PostSharp was applied once again to the project, where this aspect was used.

So if your aspect don't fire - check your PostSharp setup in projects that use aspets.

Related questions and answers:

Thanks to @Jakub for guiding comment!

Community
  • 1
  • 1
Nozim Turakulov
  • 869
  • 1
  • 9
  • 19