0

PostSharp gives this error:

PostSharp: Cannot apply an OnMethodInvocation aspect (...) with target-site weaving on the abstract or external method "...". Consider excluding the aspect from this method or use call-site weaving.

Suggested call-site weaving is not an appropriate solution for me. Is there any way to add pre/post processing for the abstract method?

2 Answers 2

1

I suggest you use aspect inheritance. The aspect will be automatically added to all methods implementing the abstract method.

See MulticastAttribute.AttributeInheritance or MulticastAttributeUsageAttribute.Inheritance, or official documentation for details.

Sign up to request clarification or add additional context in comments.

2 Comments

Looks like what I need, but it doesn't work correctly with OnMethodInvocation aspect. Any ideas? BTW, your documentation behaves very oddly in Opera browser.
OnMethodInvocation should work even with inheritance. Check with Reflector to understand what happens.
0

This is of course imposible - how would you perform target-site weaving with an abstract method, a method without any code? You can of course perform target-site weaving with all derived types implementing the method, but this requires that you control this types. Or you could make the method non-abstract and virtual and require derived types to call the base implementation.

3 Comments

There is at least one way to make it possible - use "template method" pattern. PostSharp already uses it for virtual methods. The same can be done with abstract methods.
"[...] way to add pre/post processing for the abstract method?" Do you mean performing some steps before or after a call in code? And what do you want to achieve with the aspect?
I just need to perform some code before and after each method from the specified group of methods. PostSharp seemed a good solution, but problem with abstract methods makes it impossible.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.