Archive

I’m excited to announce the release of PostSharp 2.1 CTP 2, available for download from our web site and from the NuGet gallery. This CTP is mostly feature complete and has zero known bugs. It includes all fixes from the 2.0 branch.

If you’re not on a tight go-to-production schedule, it’s pretty safe to give this version a try now. Unlike with the previous CTP, we will be in “continuous delivery” mode and will be able to release hot fixes very quickly.

So what’s new in PostSharp 2.1? I’ll be blogging about individual features the next days. Here is a short summary:

  • Build-time performance improvement
  • NuGet packaging and improved no-setup experience
  • Extensions to the System.Reflection API
  • Architecture validation (constraints)
  • Support for obfuscation
  • Support for Silverlight 5
  • License management

Build-Time Performance Improvement

Most users will see some improvement in the build-time performance of PostSharp, but for some users it could even mean a 500% speed up. The main reason? We completely rewrote the last step of the PostSharp pipeline: writing the modified assembly back to disk. The previous implementation was based on ILASM, which scaled badly for very large assemblies. The new implementation is fully written in unsafe C# and is probably the fastest available. Other improvements are due to a better utilization of multiple cores, although PostSharp remains largely a single-threaded program. For details about this feature, see our CTP 1 announcement.

This feature is available on all editions of PostSharp.

NuGet Package and Improved No-Setup Experience

PostSharp 2.1 can now be added to your application directly from Visual Studio thanks to NuGet. No need to run a program with elevated privileges. No need to edit your project file if you want to put PostSharp in your source repository. Everything is done by the NuGet package installer.

You can now use the Visual Studio Extension (VSX) even if you don’t want to run the setup program. The first time you (or your colleague) will build a program using PostSharp, a dialog box will ask you whether you want to install the VSX. No elevated privileges needed. When you deploy a new version of PostSharp to the source control, all developers get the updated VSX.

Thanks to NuGet, it will become much easier for vendors and open-source projects to include a dependency to PostSharp. Our friends at Gibraltar Software already uploaded their application monitoring agent, and will soon update it to include the dependency to the PostSharp package.

This feature is available on all editions of PostSharp.

Extensions to the System.Reflection API

How many times did you want to get the list of all classes in your assembly deriving from System.Forms.Control? Sure, you can enumerate all types and build the index yourself, but it’s quite CPU expensive. Since PostSharp already computes this information internally, it seemed natural to expose it to the PostSharp.dll library. The PostSharp.Reflection.ReflectionSearch class offers methods that allow you to search for:

  • All custom attributes of a given type (or derived type);
  • All custom attributes on a given declaration (including those added through MulticastAttribute);
  • All types derived from a given class or implementing a given interface;
  • All methods, fields or types referenced in the body of a given method;
  • All methods using a given method, field or type in their body;
  • All types, methods, fields, properties, events or parameters referencing a given type.

Note that this functionality is only available at build time. This feature is available on the Professional Edition only.

Architecture Validation (Constraints)

Many people used “empty” aspects that just did one thing: validate the code. You now have a better way to validate your code: constraints (namespace PostSharp.Constraints). As aspects, constraints are custom attributes that you put on your code. They contain code that gets executed for every assembly referencing this code. The constraint logic typically queries the current assembly using reflection and the newly introduced reflection extensions, and emit errors or warnings to Visual Studio. Since your code can use LINQ, you have a very powerful toy to play with! PostSharp comes with off-the-self constraints:

  • [Friend], applied to an internal declaration, will raise an error if the declaration is used in a different namespace than the current one. It can be used to enforce isolation of components, and gives a level of visibility that stands between private and internal.
  • [InternalImplements], applied on public interfaces, will raise an error if the interface is implemented in a different assembly. Use this constraint when you need to expose an interface but don’t want the users of your API to implement it, because you want to reserve the right to add new methods to the interface. PostSharp SDK is full of such interfaces that can be consumed but not implemented.
  • [Internal], applied on a public declaration, will raise an error if the declaration is used in a third assembly. It can be used when you don’t want users to reference a part of the API, but have to make it public for technical reasons.

Note that architecture validation is disabled by default. You need to enable it in your project properties (“PostSharp” property page). This feature is available on the Professional Edition only.

Support for Obfuscation

Let me start with a disambiguation: PostSharp does not become an obfuscator with this feature. It just became compatible with some obfuscators.

In previous versions, you could get into serious problems if you tried to use PostSharp and any obfuscator in the same project. PostSharp relied on some metadata references that were broken by the obfuscator because of renaming, so you got runtime exceptions. This is obvious if, for instance, you had a field of type MethodInfo in your aspect. The method name was stored in the serialization stream and the obfuscator did not know how to modify it. There were other less obvious cases with aspects on generic methods.

PostSharp 2.1 can be made aware of obfuscators and write metadata references in a way that obfuscators can understand and modify. But the obfuscator has also to be aware of PostSharp.

We implemented support for Dotfuscator because it is the market leader and has a free edition that ships with Visual Studio. According to the feedback we get from this CTP, we will publish our specification so that other vendors can implement it if they are interested.

This feature is available on the Professional Edition only.

Support for Silverlight 5 Beta

PostSharp 2.1 supports Silverlight 5 applications. What to add? This feature is available on all editions.

License Management

First of all, we chose to rename the community edition to Starter Edition. We got too many questions whether the community edition can be used for commercial project. We hope the new name makes the answer clear: yes, you can use the Starter Edition in commercial projects, you will just enjoy less features than with the Professional Edition.

At SharpCrafters, our license enforcement policy is to trust the customer to respect the license agreement. That’s why there was no license enforcement in version 2.0. It was not just a priority. But we may have been too liberal by letting people deploy the license key in the source control: for many companies, it meant that nobody knew how many developers were using the product. We strongly believe in trust, but we think that we should provide tools for proper license management. So we did a few changes.

We chose to deprecate deployment of license keys through source control because we want some mental process to take place when a developer first starts using the product: he also needs a license. We provide a license metering solution: we will monitor how many people install the license on their computer, but we will never block them. If we that believe a license key is being used too many times, we will simply contact the one who purchased the license key and discuss a solution. But we trust you in first place. By requesting license installation by each user, we are just asking that every company maintains a record of who is using the software.

What if manual license bookkeeping is impractical? For these situations, we provide a license server (technically: a simple ASP.NET application backed by an SQL database). The license server maintains the list of leases and ensures that the license agreement is respected. It will send emails to the license administrator (or team leader, or whomever else) when new licenses should be acquired – and you will get a 30-day grace period to purchase them. We tried to make the license server a valuable tool for the customer. You are free to modify the underlying database at will if it makes sense. You as the customer are responsible for respecting the legal agreement and we trust you.

The license server will be available with a new type of licenses called corporate licenses, that will be available for a premium (likely +30% compared to the normal commercial license).

Upgrade Today

The upgrade is free for anyone. I am pretty confident of the quality of this release so it’s a great time for you to download it. Submit all your changes to source control, do the upgrade, rebuild, and run your unit tests. If it fails, shelve the changes and report the issue. We do a lot of internal testing, but we need your feedback to move quality of this release forward.

In the next days, I’ll try to blog about individual features of this release.

Happy PostSharping!

I’m excited to kick off the PostSharp speaking tour, which will give me 8 speaking opportunities in the next 2 months.

Developer! Developer! Developer!

My first stop will be Glasgow, Scotland on Saturday May 7 at DDD Scotland 2011. I’ll be in town from Friday evening to Sunday afternoon and there’ll be plenty of opportunities to meet up. I’m happy that the community wants (and voted) to hear more about aspect-oriented development. And yes – even if running SharpCrafters takes a lot of dedication, I still feel myself a developer above all, and am still very reluctant to use the term CEO (which I find inadequate for small companies anyway).

Belgium

As a prelude to the speaking tour, I did a 3-stop trip to Belgium. On March 7th, I presented aspect-oriented programming in a (quite) non-technical way at La journée agile. This was a great event, and was my first public speaking in my native tongue since university! The audience was mainly composed of managers. The day after, I did a second presentation in French for DotNetHub. The recording is available here. Finally, on March 11th, I presented AOP to VISUG, but this time in English. Special thanks to Pierre-Emmanuel for securing these events.

After Glasgow, I’ll have one week in office where some of you will learn more about the next CTP.

Germany

During the week of May 18th, I will literally tour Germany (by train) and visit local user groups. This week will be crazy: Regensburg on Monday, Munich on Tuesday, Ulm on Wednesday, and Karlsruhe on Thursday. And now the worse: a 12 hour night trip by train to get back home in second-class day coach.

Since Germany cannot be toured in one week, I continue on June 6th with a visit of the Hamburg user group on Monday and Cologne on Tuesday.

We wanted to continue the tour, but had to cancel the next stops to fight directly to a first-class conference:

NDC, Oslo

Developers want to hear about AOP. And AOP is not just me: there will be a whole track on AOP and IoC at NDC 2011, featuring (Day 3, Track 5):

  • 9h00: Produce Cleaner Code with Aspect Oriented Programming (me)
  • 10:20: Advanced Aspect Oriented Programming (Donald Belcham)
  • 11:40: Ten Simple Rules for Rewriting IL on the CLR (Philip Laureano, author of LinFu)
  • 13:40: Inversion of Control containers: patterns and anti-patterns (Krzysztof Kozmic, maintainer of Castle DynamicProxy)

And because so many evangelist of different AOP churches, we organized a discussion panel on Day 2, moderated by Carl Franklin and Richard Campbell of .NET Rocks!

If you will be NDC, be sure to attend the panel, and prepare your sharpest questions!

Back home

I’ll be home most of the summer and the autumn, assisting my wife as we and our 3 kids are expecting the delivery of twins for September.

A single exception: I’ll be at the See# Party in Switzerland on August 19th to make sure I reached absolutely all German speakers (Kreuzlingen is at the border between Austria and Switzerland).

Special thanks to Britt, our community dude, for organizing these speaking engagements while I am coding.

More

Twelve speaking engagements in a semester is a lot, but it’s not enough to spread the word to everybody. Fortunately, I’m not the only AOP speaker on earth. Our friends Marcus King, Marko Apfel, Donald Belcham and Matthew Groves are doing good work too. Check our community page to find an event in your region. And of course, if you want to be a speaker too, we can offer you free consulting and materials to help you get started.

Happy PostSharping!

-gael

We just published the fifth maintenance release of PostSharp 2.0, correcting 29 bugs, mostly minor. The most significant improvement of this update is a solution to the number-one problem of PostSharp 2.0: its failure to load dependencies to C++ assemblies. The reason of the problem is that the CLR cannot load C++ assemblies when it is “hosted” (PostSharp hosts the CLR as SQL Server does). The solution proposed in this release is to load such assemblies for metadata only, i.e. do not load it with the CLR. This should be enough most of the time.

Even if you had no problem with previous versions of PostSharp, you may want to update to this version because it addresses an important run-time performance defect with OnExceptionAspect: the binding code was erroneously generated out of the catch block, so it was executed even when the aspect was not invoked. This issue is now solved.

This release is therefore a recommended upgrade for anyone.

Here’s the complete list of fixed issues:

  • Add possibility to specify the location of ILASM
  • Added support for Aspect.AspectPriority in Silverlight
  • AnnotationValue.FromObjectConstruction does not respect module translation
  • AnnovationValue.ToObjectConstruction does handle constructor arguments properly
  • Aspect MethodImplementationAspect missing from Silverlight build
  • Aspects inherited across assemblies are not visible in the Visual Studio Extension
  • AspectTypeDependencyAttribute does not work on Silverlight
  • Assemblies loaded by the native host may be given insufficient permissions
  • Assembly-level MulticastAttribute does not respect AttributeTargets=Struct/Delegate/Enum/...
  • AssemblyLoadException when loading mixed-mode assemblies, even when not required by PostSharp
  • Comparing method signatures ignores the method arity
  • Exception thrown on invalid lexical scopes
  • Expose the method Platform.LoadAssemblyFromFile to PostSharp.dll
  • Extension for VS2010 installed in wrong directory if VS is installed in non-default location
  • Generic parameter constraints are not loaded properly when lazy loading is enabled
  • Incorrect behavior when an IAspectProvider provides an invalid ObjectConstruction
  • Invalid code generation when IInstanceScopedAspect has explicit (private) implementation
  • IValidableAnnotation not executed if no aspect is included in the project
  • MulticastAttribute: symbols < and > in regular expressions are incorrectly escaped
  • NullReferenceException when introducing a method with custom attributes on parameters
  • OnExceptionAspect generates suboptimal code
  • PostSharp 2.0 is not side-by-side compatible with PostSharp 2.1 when a project references both versions
  • PostSharp emits PE32+ headers instead of PE32.
  • PostSharp.Aspects.Arguments implements IList
  • Sample database not included with the ContactManager example
  • Several issues with ExternalAspects in Silverlight
  • System.InvalidCastException: Unable to cast object of type PostSharp.Hosting.DotNet.ManagedDotNet40Platform' to type 'PostSharp.Hosting.NativeDotNetPlatform'.
  • Update check process throws exception on build servers
  • With MSIL serialization, system properties of MulticastAttributes are serialized, but should not

Next milestone: PostSharp 2.1 CTP 2.

Happy PostSharping!

-gael