Click here to Skip to main content
15,907,905 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i've class libraray which has two class files separately, one class file has a post sharp's aspect code as follows,
[Serializable]
    
        public class TimingAspect : PostSharp.Aspects.OnMethodBoundaryAspect
        {
            [NonSerialized]
            Stopwatch _StopWatch;

        public override void OnEntry(PostSharp.Aspects.MethodExecutionArgs args)
            {
                _StopWatch = Stopwatch.StartNew();

                base.OnEntry(args);
            }

            public override void OnExit(PostSharp.Aspects.MethodExecutionArgs args)
            {

                StackFrame frame = new StackTrace().GetFrame(1);
                System.IO.StreamWriter file = new System.IO.StreamWriter("D:\\execution time.txt", true);
                file.WriteLine(frame.GetMethod().DeclaringType.FullName + "-------" + frame.GetMethod().Name + "-----" + _StopWatch.ElapsedMilliseconds);
                file.Close();

                base.OnExit(args);
            }
        }


other class file has a assembly declaration as follows
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Reflection;
[assembly: AspectLibrary.TimingAspect(AttributeTargetTypes = "Employee.*", AttributeTargetMembers = "Page_Load",AttributePriority=1)]

to add that aspect to all the namespaces of my project, and i've referenced this class library to my project, but attribute won't apply to the name spaces of my projects

What I have tried:

tried to add separate libraries for each class, and if i add that assembly declaration class inside the project ,it works, but i want it to be outside
Posted
Updated 21-Sep-16 6:20am
v2
Comments
OriginalGriff 21-Sep-16 2:57am    
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind.
Perhaps a simple example of the files and error messages would help us understand exactly what you are trying to do?
Use the "Improve question" widget to edit your question and provide better information.

1 solution

Assembly-level attributes apply to the assembly in which they are defined - in this case, your PostSharp class library.

They do NOT apply to every assembly that adds a reference to your assembly.

You need to add the assembly attribute declaration to every project where you want your PostSharp aspect to apply.
 
Share this answer
 
Comments
Member 12677894 22-Sep-16 2:25am    
okay got it,
but is there a way i can put time aspect attribute to all classes under employee namespace by just referencing a dll to my project
Richard Deeming 22-Sep-16 7:44am    
No.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900