10 comments on “Applying aspects to 3rd party assemblies using PostSharp

  1. Gleb, you can use this approach for MVC assemblies, yes. Obfuscated assemblies will most likely not work depending on what you’re trying to do. Sometimes the meta data is far too scrambled to be useful and PostSharp will error out. Please give it a try though.

  2. This looks exactly like what I want to do. I tried it out using this exact example (PostSharp is now at version 2.1.5.1), but it doesn’t work. The aspect and aspect provider classes build, and the CIL executable runs without apparent problem.

    The resulting code contains an ExampleClass.z__Aspects class, but it’s empty. And the disassembled methods don’t contain any aspecting code whatsoever.

    Any idea what might be going wrong here?

    I may be missing a parameter or two, but the CIL executable doesn’t seem to be documented, at least to the degree where the parameter options are enumerated.

    Josh

    • Mystery solved. I ended up passing an object derived from IAspect (which is empty) instead of IOnMethodBoundaryAspect.
      It works quite nicely. Thanks very much.

  3. Pingback: planetgeek.ch » Unleash your code with PostSharp

  4. Hi when i am running your code i am getting following error as

    MyProviders.TraceAspectProvider’ does not implement interface member ‘PostSharp.Aspects.IAspectProvider.ProvideAspects(object)’. ‘MyProviders.TraceAspectProvider.ProvideAspects(object)’ cannot implement ‘PostSharp.Aspects.IAspectProvider.ProvideAspects(object)’ because it does not have the matching return type of ‘System.Collections.Generic.IEnumerable’.

    Do not know how to proceed….

    Waiting for your response

  5. Using the generic type ‘System.Collections.Generic.List’ requires 1 type arguments

    This error is also i am getting

  6. Pingback: Inject Aspect to a method using PostSharp IAspectProvider

  7. Hi,
    First I would like to thank you for this great article.
    I am currently working on 3rd party office PIA’s. I want to apply aspects to these assemblies
    for mainly logging the errors as described in this blog.
    this functionality is undocumented and not officially supported by postsharp.
    I am not sure about what kind of risks it may cause.
    I know the risk will depend on my PIA’s. What would be the general risks I need to consider before following this approach?

    Little background on my approach:
    MyProviders is very simple. I am only interested in OnException(MethoExceptionArgs args).

    [Serializable]
    public class SomeTracingAspect : IOnMethodBoundaryAspect
    {
    public void OnEntry(MethodExecutionArgs args)
    {

    }

    public void OnException(MethodExecutionArgs args)
    {

    myMessageBox custMsg = new myMessageBox( args.Exception.Message);
    custMsg.ShowDialog();

    }

    public void OnExit(MethodExecutionArgs args)
    {

    }

    public void OnSuccess(MethodExecutionArgs args)
    {
    }

    public void RuntimeInitialize(MethodBase method)
    {
    }

    }

    MyMessageBox class has these functionalities
    1.copytoclipboard
    2.emails the error and stores in the database.

    Thanks

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s