Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

postsharp exception is null

Tags:

c#

postsharp

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

like image 997
Müsli Avatar asked Oct 10 '22 08:10

Müsli


1 Answers

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/

like image 128
Dustin Davis Avatar answered Oct 12 '22 21:10

Dustin Davis