Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PostSharp on assemblies I don't have source for

In the examples on their website, PostSharp has a demo of intercepting calls in main system assemblies. I have tried a few times to setup and replicate said intercept calls on assemblies I don't have the source code for with no success.

My approach was to simply place the assembly level attribute targeting the namespace and method I wanted to instrument. This has never worked for me.

something like:

[assembly: Trace("MyCategory", AttributeTargetTypes = "My.BusinessLayer.*")]

Am I missing something here? Can I not do a runtime injection of my instrumentation aspect on a assembly if I don't have the source pulled in for it? I thought I could do runtime injections...

Thanks.

like image 864
pinvoke Avatar asked Jul 07 '10 16:07

pinvoke


1 Answers

You can trace methods of other assemblies by specifying:

[assembly: Trace("MyCategory",
                 AttributeTargetAssemblies="xyz",
                 AttributeTargetTypes = "My.BusinessLayer.*")]

However, the external assembly will not be modified! Only calls from the current project to the external assembly can be modified.

It is currently not easy to modify assemblies you don't have the source of. This is possible, but is considered an advanced scenario and requires custom coding.

like image 54
Gael Fraiteur Avatar answered Sep 29 '22 00:09

Gael Fraiteur