开发者

PostSharp OnMethodBoundaryAspect OnEntry Not Executing

I am running a .NET 4.0 Web Application (not web site) and PostSharp 1.5. I cannot get the OnEntry override method to execute using the OnMethodBoundaryAspect base class. Here is some relevant code:

public sealed class MonitorAttribute : OnMethodBoundaryAspect {

    public string[] SomeValue { get; protected set; }         

    public MonitorAttribute (params string[] someValue){
        SomeValue = someValue;
    }

    public override void OnEntry(MethodExecutionEventArgs eventArgs){
        // do Something here
        base.OnEntry(eventArgs);
    }

}

public sealed class MyUsageClass : IMyUsageClass {

    [Monitor(new string[]{ 'Test' })
    public void SomeMethod {
        // Do something else开发者_运维百科 in here
    }        

}

Am I missing something? It never hits the OnEntry method. I also tried replacing my PostSharp.dll and PostSharp.Laos.dll dependencies with the new 2.0 version. If it makes any difference MyUsageClass is instantiated by StructureMap.


Yes, every dev will need to have PostSharp installed. If you're just using the starter edition then it's all free.

Posting this as an answer to show you the code. My test code

class Program
    {
        [Monitor]
        static void Main(string[] args)
        {

        }
    }

    [Serializable]
    public class MonitorAttribute : OnMethodBoundaryAspect
    {
        public override void OnEntry(MethodExecutionArgs args)
        {
            Console.WriteLine("OnEntry");
        }
    }

The code after compilation

internal class Program
    {
        [CompilerGenerated, DebuggerNonUserCode]
        internal sealed class <>z__Aspects
        {
            internal static MethodBase m1 = MethodBase.GetMethodFromHandle(ldtoken(Main()));
            internal static readonly MonitorAttribute a0 = (MonitorAttribute)<>z__AspectsImplementationDetails.aspects1[0];
        }
        private static void Main(string[] args)
        {
            Program.<>z__Aspects.a0.OnEntry(null);
        }
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜