Müsli
Müsli

Reputation: 1774

postsharp exception is null

I have a probleme with Postsharp.

i have this:

 [Serializable]
 public class MethodConnectionTracking: OnExceptionAspect
 {
  public override void OnException(MethodExecutionArgs args)
        {
            base.OnException(args);
        }
 }

and i used like this. In assemblyInfo.cs:

[assembly: MethodConnectionTracking]

so, when an exception occurs in the assembly its executes OnException method. But, when i debug the method and i watch args (type: MethodExecutionArgs ) every property has a null value. args.Exception is null. And i need the exception type..

Anyone knows how can i fix this?

Thanks in advance

Upvotes: 4

Views: 512

Answers (1)

Dustin Davis
Dustin Davis

Reputation: 14605

The answer if because PostSharp sees that you are not using any of those properties so it implements optimizations to not do anything with those properties. that is why they are null when you debug. change your aspect to match the following ocde then try to debug again

[Serializable]  
public class MethodConnectionTracking: OnExceptionAspect  
{   
public override void OnException(MethodExecutionArgs args)         
{             
Exception e = args.Exception;     
}  
}

you can see exactly why here: http://programmersunlimited.wordpress.com/2011/08/01/postsharp-why-are-my-arguments-null/

Upvotes: 4

Related Questions