Postsharp OnException Aspect not Working as Expected

.net, c#, postsharp

Solution

IMHO AutoLogExceptionsAspect is not related to onexception aspect (or at least is not mandatory).

Usually when Exception (or other "methods" aspects attributes) are not called, it is because there was a problem in build chain at PostSharp call time.

Please get sure if Postsharp is up and running on build machines, and Postsharp is enabled in project properties (for example, no "SkipPostSharp" switch in properties on assemblies which needs PostSharp to be processed). If not attributes won't be executed.

Problem

I have the following custom aspect, and have tried applying it at project and class level. In all cases, even an intentional divide by zero, the `OnException` method is never called. What am I doing wrong? ``` [Serializable] public class AutoLogExceptionsAspect : OnExceptionAspect { public override void OnException(MethodExecutionArgs args) { AutoLogExceptionEventSource.Log.AutoLogException(args.Exception.GetType().Name, args.Exception.Message, args.Exception.StackTrace); args.FlowBehavior = FlowBehavior.Continue; } public override Type GetExceptionType(MethodBase targetMethod) { return typeof(Exception); } } ``` I have tried this decoration on a class: ``` [AutoLogExceptionsAspect] public partial class App : Application ``` and this one on the project: ``` [assembly: AutoLogExceptionsAspect] ```

Original source