0

I have several methods that are using an attribute I built with the help of PostSharp. The attribute has 3 constructor overloads and each overload performs logic before the OnEntry() is called. The first time a method is hit with my attribute on it, it works fine. After that, the constructors are not being hit in my attribute and only the OnEntry() is firing.

I need the constructors to be called each time the method with the attribute is called. Does anyone know a solution for this?

Thanks in advance.

spyter
  • 727
  • 1
  • 9
  • 25
  • You mean constructor of an Attribute? it is firing only once probably at compilation time. – Ilya Ivanov Nov 08 '12 at 16:03
  • yes the attribute constructor. When I enter the method for the first time, the constructor is fired. After that, entering the method does not trigger the constructor code. – spyter Nov 08 '12 at 17:05

2 Answers2

1

You can see another topic, which shows when constructors are run: When is a custom attribute's constructor run?

Postsharp access there attributes right after compilation, but before execution (this is called post compilation). The debugger is working properly for it, so you really can set a breakpoint at constructor and see the call stack to observe from what place this constructor was called.

Community
  • 1
  • 1
Ilya Ivanov
  • 23,148
  • 4
  • 64
  • 90
0

Attribute constructors are not executed in the run time. PostSharp attributes are no exception for this rule.

I believe you'd have to redesign your approach. I am even suprised you claim that your constructor is hit once. I just check it and the attribute constructor is not hit at all in the run time.

Wiktor Zychla
  • 47,367
  • 6
  • 74
  • 106
  • Thanks for the feed back! Yes, my attribute constructor is hit once when the method is first called.. weird. – spyter Nov 08 '12 at 17:06
  • It is not. The constructor is hit in the compile time. You have probably mistaken the compile time and the run time. This means that upon consecutive runs, when there is NO compilation, your constructor will NOT be invoked, as I've said. – Wiktor Zychla Nov 08 '12 at 19:02