Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
335 views
in Technique[技术] by (71.8m points)

c# - 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...