Since its inception, PostSharp had always allowed making Aspect-Oriented Programming in .NET easy, allowing developers to produce cleaner code, encapsulating infrastructure code behind reusable modules.
We are pleased to announce today that we are making this even easier – with PostSharp Toolkits!
What are PostSharp Toolkits?
PostSharp Toolkits are a collection of ready-made solutions for adding common infrastructure code, such as logging, exception handling and performance monitoring to your application with no changes to your source code! Powered by PostSharp, the most complete AOP solution for .NET, the PostSharp Toolkits build upon the raw power of Aspect-Oriented Programming to seamlessly apply those solutions throughout your application.
Sounds interesting, how does it work?
We have great examples on how to add things like logging, tracing, and exception handling to your code. We’ve built upon this knowledge, and added things like XML-configuration, so no changes in the source code are required! Simply grab the toolkit from NuGet, and you’re all set!
What toolkits currently exist?
With the first release, we’re introducing the PostSharp Diagnostics Toolkit – an instrumentation toolkit that adds diagnostics features, such as logging, exception handling, performance counters and feature tracking to your application. The PostSharp Diagnostics Toolkit includes pluggable support for the leading logging frameworks, such as NLog. Support for additional frameworks is coming soon!
Note: As this is a work in progress, the PostSharp Diagnostics Toolkit currently only has logging support, with a very limited feature set. In the following releases, we will introduce additional configuration options, support for popular frameworks and other cool stuff!
The source code for the PostSharp Toolkits is available on GitHub, and we’re going to introduce new features based on your feedback in short release cycles.
Getting started
Here is how to add logging to your application without changing a single line of code:
Starting with a simple project:

- Step 1: Add the PostSharp Diagnostics Toolkit from NuGet to the assembly you wish to instrument. It downloads PostSharp automatically as a dependency (please note that you need PostSharp 2.1 SP1 or higher for the PostSharp Toolkits).

- Step 2: Rebuild your application
When you now run your application, this is what is printed in the output:

How did this happen?
The NuGet installation creates a .psproj file named after the current project in the source tree. This is an XML file, containing the configuration, which is processed by PostSharp during compilation.
The details about the XML configuration will be posted on GitHub. For now, just note that in the <Data> section there is a definition of LogAttribute. This is equivalent of placing the LogAttribute (part of the toolkit) on an assembly level in the source code, via:
[assembly: LogAttribute]
By default, it will be applied to all methods of the application. You can use the Filtering Properties to limit the multicasting. Please refer to the Online Documentation for details.
If we take a look at the compiled assembly in our favorite decompiler, we can see that the output lines were added directly in the method bodies, and no reference to PostSharp.dll is required!

What about writing the output to a file?
Glad you asked! The PostSharp Diagnostics Toolkit for NLog is exactly the solution for writing the output to NLog. Install it from NuGet, it will download all the required dependencies automatically. You will then need to configure NLog (either manually, or by downloading a NuGet package NLog.Configuration, which contains a sample configuration file for NLog). Then simply rebuild your application, and NLog will be automatically added to it!
Few notes:
The PostSharp Toolkits project is built using the PostSharp SDK. The PostSharp SDK is completely unsupported and undocumented, for the reasons detailed in this blog post. While the source code is available on GitHub, any questions pertaining to the PostSharp SDK will go unanswered.
The PostSharp Toolkits is an ongoing project, we are aiming at short (2-week) release cycles, bringing you more features based on your feedback!
Questions? Suggestions? Bugs?
Please visit our dedicated PostSharp Toolkits Support Forum to let us know what you think!
Happy PostSharping!
-Igal
I’m happy we finally refreshed our front-page download and released PostSharp 2.1 SP 1, featuring 48 bug fixes and user stories.
All fixes were already available under the “download” section, so it’s not that anyone had to wait so long to get a solution.
This service packs solves virtually all defects that have been reported to us, most notably:
- compatibility with Code Analysis (FxCop) – the infamous file locking issue
- compatibility with Code Contracts (issues with debugging symbols)
- compatibility with Silverlight 5
- issues in PostSharp HQ when upgrading PostSharp
This makes this release a very stable one. For a list of all fixes, see the release notes.
The SP 1 contains the following new enhancements:
- View source code enhanced by PostSharp from Visual Studio using your favorite decompiler.
- Example code migrated to Visual Studio 2010 and cleaned up, licensing under BSD 2.0.
- Refresh (actually, revival) of the XML project system:
- Unification of plug-in configuration (psplugin) and project configuration (psproj).
- Support for services that do not refer to PostSharp.Sdk.dll.
- Support for data islands inside XML project files.
- Adding aspects (actually, MulticastAttribute) to an XML project file – so without changing anything to source code.
The last few enhancements can appear a little cryptic to you, but they open the way to a new line of features we’ll blob about from next weeks: PostSharp Toolkits. They will make it easier to use the power of PostSharp without the difficulty of learning aspect-oriented programming.
Happy PostSharping!
-gael
Wow! What a turnout for my first webinar! Thank you all for attending, I had a great time presenting it, and will continue to do more webinars in the future. The webinar was recorded, and the video is now online for your viewing:
As promised, here are the answers to the great questions you asked, which I didn’t have the chance to answer during the live webinar. As always, you can always ask your questions on our Support Forums.
Q: Any reason the [aspect] class must be Serializable?
A: At (post) compilation, the aspect is serialized using binary serialization, and added as a resource to the target process. Then at runtime, the aspect is deserialized. PostSharp will emit a compilation error if you forget to mark your aspect as Serializable.
Q: What is the typical use case for creating interfaces using PostSharp?
A: One typical scenario for implementing interfaces with PostSharp is implementing INotifyPropertyChanged in WPF to support Data Binding.
Q: Are the OnExit and OnEnter aspects thread safe? How would one make it thread safe if it is not?
A: While the aspects themselves are thread-safe, shared state (i.e. custom fields) within the aspects is not. To safely pass data around between OnEnter and OnExit events, you can use the MethodExecutionArgs.MethodExecutionTag property.
Q: What about signed DLLs and PostSharp?
A: PostSharp has no problems with signed DLLs – they will be re-signed after the post-compilation process.
Q: What about Silverlight DLL's, is it also available?
A: Of course, PostSharp comes with the Silverlight assemblies included, you need to add a reference to the PostSharp.SL.dll instead of PostSharp.dll. For more information, please refer to the online documentation.
Q: Can you provide a good definition of aspect oriented programming?
A: Aspect Oriented Programming complements traditional OOP by allowing us to encapsulate infrastructure code (such as logging, security, validation, etc.) into small modules called aspects, and then apply those aspects throughout the entire system in such way that the business logic is completely separated from those concerns.
So go ahead, download the free starter edition now!
Happy PostSharping!
-Igal
Boilerplate code. It’s all around us, polluting our business logic, and forcing us to write the same code over and over again. Join us on Thursday, January 26th, as our very own Igal Tabachnik shows you how to stay DRY (Don’t-Repeat-Yourself) by using aspect-oriented programming (AOP) and PostSharp to remove boilerplate code that’s duplicated in and across systems.
Attendees will learn:
- Why the DRY principle matters
- How AOP helps to remove boilerplate code
- How to use PostSharp to produce cleaner code
- Real-world AOP usage examples
Oh, and that’s not all – we’re giving away two PostSharp licenses to two lucky attendees!
So hurry up, sign up here: https://www3.gotomeeting.com/register/724468246
During compilation, PostSharp takes great care in making sure that everything works correctly. When something goes wrong, PostSharp will report it as an error or a warning. Until now, however, whenever an error or a warning occurred, the developer had to manually navigate to that place in code.
We are excited to announce that with PostSharp 2.1 we’ve enhanced the errors and warnings with the exact location information, allowing you to simply double-click on the message and you’ll be taken to the error line!
To enable this feature, go to Tools – Options – PostSharp, and under Experimental, set Resolve Message Location to True:

Then, simply rebuild your solution, and if there are any warnings or errors, you’ll be able to see exactly where they are:

This is accomplished by specifying the member (in this case, the method) that is responsible for the message, in the aspect’s CompieTimeValidate method:
// Validate the attribute usage.
public override bool CompileTimeValidate( MethodBase method )
{
// Don't apply to constructors.
if ( method is ConstructorInfo )
{
Message.Write( method, SeverityType.Error, "CX0001",
"Cannot cache constructors." );
return false;
}
MethodInfo methodInfo = (MethodInfo) method;
// Don't apply to void methods.
if ( methodInfo.ReturnType.Name == "Void" )
{
Message.Write( method, SeverityType.Error, "CX0002",
"Cannot cache void methods." );
return false;
}
// Does not support out parameters.
ParameterInfo[] parameters = method.GetParameters();
for ( int i = 0; i < parameters.Length; i++ )
{
if ( parameters[i].IsOut )
{
Message.Write( method, SeverityType.Error, "CX0003",
"Cannot cache methods with return values." );
return false;
}
}
return true;
}
Aspect developers are encouraged to include the member in error/warning messages. For more information, please refer to the documentation on Working with Errors, Warnings and Messages.
Please note that this is not enabled by default as it is still experimental and might have an impact on performance. Please let us know how it works out for you!
Happy PostSharping!
-Igal
As most of you know, PostSharp’s transformation (weaving) of aspects into your assemblies happens after the compilation. One of the most requested features is the ability to see the actual code that is produced by PostSharp. Until now, you had to manually open the newly compiled assembly in your favorite decompiler to see the produced code.
We are delighted to announce that we’ve made viewing the source code in your favorite decompiler much easier – via a single click on the enhanced class or method:

By clicking the See enhanced source code link for the first time, you will be asked to select the decompiler you want to use (we currently support dotPeek, ILSpy and Reflector). You can always change the decompiler later from Tools – Options – PostSharp:

From now on, when you click on the See enhanced source code, your chosen decompiler will open and show you exactly the source code, as it was modified by PostSharp!

This feature is available in the latest version of PostSharp!
Happy PostSharping!
-Igal

If learning more about Aspect Oriented Programming is on your to-do list for 2012, we have some very good news for you.
We’ve teamed up with the good folks at Pluralsight to make it easier than ever for developers to get up to speed on developing with aspects. PostSharp users can sign-up to receive a free 30-day trial membership good towards one Pluralsight online course.
Start learning about Aspect Oriented Programming for .NET today >>
Pluralsight, “the leader in high-quality online training for hardcore developers,” has a huge library of online courses to choose from but, naturally, the course we recommend is Aspect Oriented Programming for .NET by PostSharp MVP and Pluralsight Author, Donald Belcham.
Donald is a senior software developer, independent contractor, author, and trainer based in Edmonton, Canada. He spoke about the topic of Aspect Oriented Programming at NDC and DevTeach Montreal earlier this year, and published the online course on Pluralsight in June.
The course is divided into four parts:
- Introduction to AOP
- AOP using Interceptors
- AOP using IL Code Weaving
- AOP beyond decorators
From Donald: “My course is perfect for developers who want to learn how to avoid code repetition by implementing AOP in .NET projects using IL Code Weaving frameworks like PostSharp, Interception frameworks like Castle Windsor, and even how to implement AOP without following the traditional decorator pattern.”
Apply for your free 30-day Pluralsight trial membership today and, upon approval, we’ll email you a unique login code plus a link to a special sign-in page for PostSharp users.
Start your free 30-day trial membership today >>
-Britt

Scott Hanselman knows tools.
As a Principle Program Manager at Microsoft, and one of the most sought-after developer speakers on the planet, Scott has his finger planted firmly on the pulse of the .NET community. Luckily for all of us, he only uses his powers for good by entertaining and educating the community about software development across a variety of channels including podcasts, presentation and speaking tips, books, and more.
Since his first ultimate tools list in 2003, the popularity and length of Scott’s annual lists have grown considerably. This year’s list includes categories such as “The Big Ten Life and Work-Changing Utilities,” “Rocking Sweet Windows 7 Specific Stuff,” and “A (.NET) Developer's Life,” to name a few.
We’re thrilled and honored to see PostSharp included in Scott’s 2011 ultimate tools list alongside so many other great tools. We know we wouldn’t have made the list without the help of our customers, MVPs, and partners. Thank you, all.
The ultimate tools list wasn’t our first run-in with Scott in 2011. Gael sat down with him in September as part of his startup podcast series, to discuss the challenges of taking PostSharp from open source to commercial business. The two talked about aspect-oriented programming and Scott rightly pointed out that AOP is another kind of abstraction, which is the whole point of what computers are supposed to do for us, work that’s not fun like logging and transactions.
Since the beginning of 2011 we’ve focused on spreading the word about the benefits of aspect oriented programming for .NET with in-office trainings, user group and conference presentations, podcasts and screencasts, white paper and blog posts.
It seems to be working.
In September, the same month as the Hanselminutes podcast, we announced a rising trend in AOP adoption among developers in large organizations, especially those in the Fortune 500, and created case studies showing how two big companies, Siemens Audiology and Thales Information Systems, are succeeding with PostSharp.
There’s more to come in 2012, and we look forward to speaking with more of you about your experience with PostSharp. Special thanks goes out to Scott Hanselman for his seemingly tireless commitment to the community and his never-ending quest to find the ultimate tools for .NET.
Happy PostSharping!
-Britt
I’m thrilled to announce that our partner IdeaBlade has just released a new version of DevForce. This application framework already provided pretty much all of the wiring you need to develop rich line-of-business applications (Silverlight and WPF backed by WCF, Entity Framework, OData). The last release now supports domain models written for Entity Framework in Code First style… and that still respect the spirit of Code First: nice, clean code, free from infrastructure boilerplate.
Guess who is writing that boilerplate for you? Right: PostSharp. What’s nice with DevForce is that you can start coding immediately and don’t have to understand anything about AOP and PostSharp since DevForce provides all the aspects you need. Even better: you don’t need to download PostSharp and you don’t have to check-out any license: all is included in the IdeaBlade package.
See! I managed to avoid the c*c*c word.
I’d like to thank Albert and his team for their efforts and feedback during the RC stage of PostSharp 2.1. I’m sure DevForce and PostSharp will benefit from each other and will make it even easier to develop strong LOB applications.
Happy PostSharping – now even to those who never heard of PostSharp.
-gael
I’m delighted to announce the release of PostSharp 2.1 RTM, available for download on our web site and on NuGet.
The last release candidate has been available as the front-page download for more than a month now with no reported bugs. PostSharp 2.1 becomes the recommended version for everyone and is now considered more stable than the 2.0 branch.
New features
PostSharp 2.1 brings the following improvements to PostSharp 2.0:
- Improved build-time performance: up to 5x faster. Read more.
- Architecture validation: build-time validation of design rules. Read more.
- Extended reflection API: programmatically navigate code references. Read more and more.
- NuGet packaging and improved no-setup deployment experience. Read more.
- Support for obfuscators: we now support Dotfuscator. Read more.
- Improved Visual Studio Extension (PostSharp tab page in project properties).
- Warnings and errors now come with file/line information. The feature is optional and must be enabled manually from Visual Studio options. We’re eager to hear feedback about this feature from customers with larger projects.
- Support for Silverlight 5 and Windows Phone 7.1.
- Compatibility with Code Contracts 4.
- Improved messaging API.
- Streamlined licensing experience and “getting started”.
- License server (optional).
- Streamlined “getting started” experience.
- Warnings can be disabled locally (for a specific element of code) using the IgnoreWarning custom attribute. See online documentation for details.
Bug fixes
The RTM fixes the following issues from RC2:
- "EnhancedByPostSharpAttribute" causes issues with the WPF compiler
- Aspected methods with parameter of generic types are not underlined in VS code editor
- Constant SkipPostSharp does not work
- Different versions of PostSharp cannot be used in the same solution
- Error due to file lock of *.vhost.exe
- Invalid version number is written in native resources
- MSBuild error "CodeContractsPerformCodeAnalysis target is missing" with Code Contracts Standard (without Code Analysis)
- Type parser throws exception with arrays or generic types
Upgrading from PostSharp 2.0
This new version is fully backward compatible with PostSharp 2.0 (except one breaking bug fix), and can be installed side-by-side with PostSharp 2.0. In order to upgrade, you should just update the references to PostSharp.dll (and possibly to PostSharp.targets, if PostSharp is installed in source control). A utility contained in PostSharp HQ helps you converting projects from 2.0 to 2.1.
The upgrade is free for everyone and your 2.0 license key will work with 2.1. However, you will be asked to enter your license key.
Even if you are happy with the features of 2.0, you have to upgrade to 2.1 because your projects are going to compile damn faster! Frankly. PostSharp has now the fastest MSIL engine on the market.
Announcing PostSharp 2.0 Update 6
By the way, we’ve also updated the PostSharp 2.0 release. It contains the following fixes compared to the previous update. Needless to say, these fixes are also included in the 2.1 release.
- Aspect instance fields should not be marked as serializable
- Aspects may conflict with themselves
- Attempt to use two adornment layers when symbol file is updated
- BaseMarkerManager.RefreshTextMarkers causes AccessViolationException
- Collapsed region names should not be underlined by the VSX
- CSharpLanguageAdapter.VisitPropertyAccessor causes CodeProperty.get_Parent to throw InvalidOperationException
- Exception in MulticastAtributeTask when a parameter-level MulticastAttribute is applied to a property
- Exception in MulticastAttributeTask with inheritance on generic methods
- Exception when an aspect is applied to a generic protected method, or a protected method of a generic type, in a third assembly.
- Exception when an aspect is applied to a virtual method of a sealed/value type
- Exception with multicasting inheritance on generic methods.
- ImportMember throws an exception when a member is a property and an accessor is missing.
- In IntroduceMember, CopyCustomAttribute with merge does not work
- Incompatibility of the PostSharp VSX with CodeRush - collapsed regions
- Invalid code generation when several OnMethodBoundary aspects are applied
- Invalid code generation with a MSIL-serialized aspect containing an array argument
- Invalid handling of generic instances in reflection wrappers
- Invalid MSIL generation when [IntroduceMember] is applied to a member with a generic type argument
- InvalidCastException when IAspectProvider is used when MsilAspectSerializer, and a non-instrinsic is passed to the ObjectConstruction
- InvalidComObjectException from SolutionWatcher constructor
- ManagedDotNet40Platform.GetGetClrIdentityManagerProc throws COMException: The handle is invalid.
- Many features MethodRefDeclaration fail when the method refers to an implicit method of multidimensional arrays
- Method-level MulticastAttributes with multicast inheritance are not multicast to derived types accross assemblies
- MSBuild step "PostSharp20CopyOutputToCodeAnalysis" can fail because of file locking
- Multicast attributes are applied to anonymous methods, but should not
- MulticastAttribute.TargetMemberAttributes is not respected for properties and events
- NullReferenceException in QuickInfoTracker.OnMouseMove
- ProjectWatcher.UpdateSymbolPath throws NullReferenceException
- Some debugging sequence points are dropped
- ToolInvocationHelper.InvokeTool process output listener causes ArgumentOutOfRangeException on
- UpdateCheckUtility.BeginRetrieveMessages throws ThreadStartException
- UpdateCheckUtility.BeginRetrieveMessages throws ThreadStartException
- VsPackage.BeginInvoke throws COMException
- Win32Exception in PostSharp.VisualStudio.HWndDispatcher.BeginInvoke
- Windows Phone 7 does not support tail calls generated by PostSharp
- WriteWeavingSymbolsTask.Execute throws UnauthorizedAccessException
What’s Next?
It has been precisely one year since I started working on PostSharp 2.1. Arguably, it took way too much time to get that release out of the door. And here’s why: most of our time was invested in building the company and spreading the work about AOP. Since July, I’ve started research and planning for the next major version of PostSharp and a new product code-named Resonance, which will be to .NET software what magnetic resonance is to human body (detailed and non-invasive imaging). We’ve hired two software developers and, while PostSharp 2.1 was maturing, we started real development on the new “thing”. You’re going to be amazed, I promise.
But today, we’ve become confident that PostSharp 2.1 is ready for production, and it’s a great time for you to upgrade.
Happy PostSharping!
-gael