Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing PostSharp OnExceptionAspect across mulit projects
    primarykey
    data
    text
    <p>Good afternoon everyone,</p> <p>I am trying to use the example "Aspect Oriented Programming Using C# and PostSharp" by Reza Ahmadi <a href="http://www.codeproject.com/Articles/337564/Aspect-Oriented-Programming-Using-Csharp-and-PostS" rel="nofollow">http://www.codeproject.com/Articles/337564/Aspect-Oriented-Programming-Using-Csharp-and-PostS</a> and dnrTV <a href="http://dnrtv.com/dnrtvplayer/player.aspx?ShowNum=0190" rel="nofollow">http://dnrtv.com/dnrtvplayer/player.aspx?ShowNum=0190</a> for the exception handling. Everything works great if the "OnExceptionAspect" is in the same project/assembly, however the event does not work if it I move the class to it own dll.</p> <pre><code>[assembly: ExceptionAspect (AttributePriority = 1)] [assembly: ExceptionAspect(AttributePriority = 2, AttributeExclude = true, AttributeTargetTypes = "HpsErp.Common.AspectObject.*")] namespace AspectObject [Serializable] public class ExceptionAspect : OnExceptionAspect { public override void OnException(MethodExecutionArgs args) { Trace.TraceError("{0} in {1}.{2}", args.Exception.GetType().Name, args.Method.DeclaringType.FullName, args.Method.Name); if (args.Instance != null) { Trace.TraceInformation("this={0}", args.Instance); } foreach (ParameterInfo parameter in args.Method.GetParameters()) { Trace.TraceInformation("{0}={1}", parameter.Name, args.Arguments[parameter.Position] ?? "null"); } } </code></pre> <p>I also created a class in the external dll for "Timing" and it works great if I add a custom attribute to the class.</p> <pre><code>namespace AspectObject [Serializable] [MulticastAttributeUsage(MulticastTargets.Method)] public class TimingAspect : OnMethodBoundaryAspect { [NonSerialized] Stopwatch _StopWatch; public override void OnEntry(MethodExecutionArgs args) { _StopWatch = Stopwatch.StartNew(); base.OnEntry(args); } public override void OnExit(MethodExecutionArgs args) { Console.WriteLine(string.Format("[{0}] took {1}ms to execute", new StackTrace().GetFrame(1).GetMethod().Name, _StopWatch.ElapsedMilliseconds)); base.OnExit(args); } Using AspectObject; namespace MyApp { public class Car { [TimingAspect] private void Drive() { //... } } } </code></pre> <p>In the end, I am hoping to have this is multi dlls so that I can reuse it ie: wcf.</p> <p>Thanks for any and all help...</p> <p>James</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload