SheepAspect Preview 3

This is not a massive release or anything. The idea is to push new changes rapidly to the public to attract early feedbacks, especially because this Preview3 release comes with a good set of new features and improvements that I genuinely feel very excited about. Many of these changes are based on feedbacks I have received from early adopters. So thanks to everyone who has shared their inputs.

What’s New

There is no significant changes on the underlying SheepAspect framework itself. This release is more of implementing new functionalities and natural progression of the feature-set of the library. Some of these new features are:

  1. The most significant new feature in Preview3 release is the Mixins support. With the new [DeclareMixin] advice, you can now statically add interface implementations to existing classes. I will write have written the details of this in a separate post.
  2. We also now have [DeclareAttributes] advice attribute. With this advice, you can statically add attributes to existing types, methods, properties, fields, and constructors. This will also be covered in the upcoming posts.
  3. IAspectAware interface, so you can now intercept when your aspects get instantiated by AspectRuntime so you can execute some initialisation routine. Again, this will be covered in the upcoming posts.
  4. A more complete set of pointcut implementations. Preview-2 advices could only target methods, properties, and instructions (method-calls, field gets/sets). In preview-3, they can also target types, constructors, fields, and property getters/setters. Events are only partially supported at the moment.
  5. Intellisense documentation. I understand that SheepAspect has a very steep learning curve. It can be overwhelming for users to get started or to figure out what each attribute does. In this Preview 3 release, most of SheepAspect’s public API is well documented.
  6. In Preview 2, SheepAspect required pdb files of all target binaries (so that SheepAspect can preserve debuggability of your weaved binaries). This has caused a problem for users who do not have pdb files of their target binaries. In Preview 3, pdb files are optional.

Get It Now

As usual, SheepAspect Preview3 is installable from NuGet: SheepAspect-Query-Analyzer for Preview-3 version is still due to come soon, and will be downloadable separately on the SheepAspect homepage.

UPDATE: SheepAspect-Query-Analyzer is now always included when you install via NuGet, under the Tools directory within the SheepAspect package folder.


12 thoughts on “SheepAspect Preview 3

  1. Thanks for your great work. Sheep.Aspect has been a huge improvement for our development. Can you give a brief description on how to use the [DeclareAttributes] attribute? Currently I have a need for adding some attributes to properties in generated code and an aspect for this could be of great help. I tried to figure it out by myself, but unfortunately I doesn’t work. Everytime the compiler crashes with

    Error : The best overloaded method match for ‘Mono.Cecil.ModuleDefinition.Import(System.Type)’ has some invalid arguments

    Do you have any idea, what could be wrong? The pointcut works when I use it with e.g. an around advice.

    1. Hi Christoph, thanks for the support.
      You’re right, DeclareAttribute syntax is really not the most obvious to work out. As a general pointer, the best place to figure out the usage syntax of certain SheepAspect API is usually the documentation comments included on each attribute, which provides some basic syntax and usage examples that will hopefully give some starting point.

      As for [DeclareAttribute], here’s an example of an aspect to declare [Transactional(IsolationLevel = “READ COMMITTED”, Scope = “RequiredNew”)] attribute to all public methods within service classes:

      public class InjectTransactionalAttributeAspect
         [SelectMethods("Public & InType:Name:'*Service'")]
         public void ServiceMethodsPointcut(){}
         [Transactional(IsolationLevel = "READ COMMITTED", Scope = "RequiredNew")]
         public void AddTransactionalAttribute(){}

      (Taken from the sample project included in the project repository:

      Hope that helps, but please do let me know if you have any difficulty. In the meantime I will fix the cryptic error message. If you could send me the sample code snippet you used to produce the error, that would be really helpful.

      1. I had a look into the code and defined the aspect as follows:

        public class JsonExportPropertyFilterAspect
        [SelectProperties("InType: 'ambiHome.Model.MyClass' & Name: 'MyProperty'")]
        public void SpecifiedProperties() { }

        // TODO DeclareAttributes doesn't work with aspect compiler :-(
        public object DeclareJsonIgnoreAttribute { get; set; }

        The class with the property is simple:

        namespace ambiHome.Model
        /// Description of MyClass.
        public class MyClass
        public string MyProperty { get; set; }

        If it helps I can provide you with a sample project.
        Thank you for helping me with this issue.

  2. Thanks for providing the sample code. Everything looks to be fine. I tried the exact same code and can’t seem to produce the error, however I have a strong suspicion that it might be down to the Mono.Cecil version. Could you clarify the exact version of Mono.Cecil.dll version referenced by the project (as well as its file-system path as provided by nuget)? Also, what .net version are you using?

    UPDATE: I managed to get the error, which is apparently caused by declaring the [DeclareAttribute] advice on a property (public object DeclareJsonIgnoreAttribute {get; set;}), as opposed to be on a method (which is currently the only supported way to define this advice). Though I can see why you need to define it on a property in your case.
    I will fix this bug shortly. Unfortunately I can’t seem to see any possible workaround at the moment. Thanks for reporting it, I’ll ping you when I get this fixed.

    1. I use .NET 4.0. The packages.config contains Mono.Cecil in version “”, but the version in the file packages/Mono.Cecil. says “”. I’m a little bit confused since Mono.Cecil is not a reference within my project.

      1. I have published the fix to Nuget. Please update your SheepAspect Nuget package (to Please let me know if it resolves your issue.

  3. And why don’t you update codeplex download section? When I first saw the project in my codeplex search results i thought it’s dead or about to be die because latest downloadable version related to 2011 year.

    1. Hi Anton. I stopped publishing the binaries via the download page since Nuget, because I didn’t see the need for the otherwise complicated installation instructions, which can be a bit discouraging to most users.

Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s