Metalama 2025.0 Generally Available: Support for C# 13 and .NET 9, Aspect Framework Improvements, and More
Metalama 2025.0 is now generally available! This release supports C# 13 and .NET 9, adds significant enhancements to the aspect framework, and boosts performance substantially.
This article highlights the most significant improvements. For a detailed discussion, see the release notes of Metalama 2025.0.
Note that we are simultaneously releasing PostSharp 2025.0.
C# 13 and .NET 9
The primary goal of Metalama 2025.0 is to support the new .NET stack. All new C# features and the new .NET SDK have been implemented and tested. This includes:
params
collectionsref
/unsafe
in iterators and async methodsref struct
can implement interfaces- Classes can have
ref struct
constraints - New escape character in strings
- Locking on the
Lock
class - Implicit indexer access in object initializers
- Overload resolution priority
partial
properties
We’ve updated third-party dependencies.
Note that the minimum supported version of Visual Studio is now 17.6 LTSC (Roslyn 4.4).
Support for code generators and interceptors
We’ve improved the integration of Metalama with code generators and interceptors. We now consistently execute source generators after any Metalama transformation.
This approach has three benefits:
- It offers a consistent experience both at design- and build-time.
- Aspects can introduce code that relies on code generators, such as the
[GeneratedRegex]
attribute. - You can now use Roslyn interceptors alongside Metalama since they no longer conflict with our code transformations.
The downside is that you can no longer use Metalama aspects in Razor (.cshtml
) pages.
Aspect framework improvements
- Closing gaps with introduced types. You can now use introduced types in type constructs like
Foo[]
,List<Foo>
,Foo<Bar>
, orFoo*
, whereFoo
is the introduced type. - Introduction of static virtual, abstract, and partial members. We’ve lifted several limitations in member introductions.
- Introduction of generic interfaces. You can now implement a generic interface without limitation. Previously, for a class
Bar
, it was impossible to implement an interfaceIFoo<Bar>
, which was crucial to implement, for instance, comparison patterns. - Introduction of extension methods. You can now introduce extension methods by adding the
[This]
attribute to the first parameter of the template method or setting theIParameterBuilder.IsThis
property. - Dynamic definition of local variables. You can now dynamically define a local variable in a T# template thanks to the new
meta.DefineLocalVariable
method, which returns anIExpression
. - Suppression of well-known warnings in aspects. We now suppress some compiler warnings in aspect code because they are generally irrelevant given the meta-programming nature of the code.
- Clean-up of IRef and overridden field representation. We’ve refactored the implementation (and, to some extent, the public API) of the
IRef
interface and made the representation of overridden fields more consistent.
Async and background WPF commands
The [Command]
aspect now supports asynchronous and background commands:
- Asynchronous commands are those that return a
Task
. - Background commands, whether synchronous or not, execute in a background thread instead of the UI thread.
Both asynchronous and background commands can be canceled through a CancellationToken
parameter.
Thanks to extensive refactoring of the code model and other efforts, we’re excited to report impressive performance improvements: Metalama 2025.0 is almost twice as fast as 2024.2 under a typical workload.
The overhead of Metalama 2025.0 is about 60% of the overhead of the previous version. You should now find your builds are between 25% and 35% slower with Metalama than without it, depending on the number of aspects. We think that’s a fantastic achievement, and it seems that performance is no longer a concern when adopting Metalama.
For precise measurements and methodology, see this blog post.
Bug fixes
We fixed 43 bugs in this release, most of them affecting the design-time experience. We are monitoring telemetry data to identify and prioritize remaining issues.
Breaking changes
As noted above, we’ve updated all third-party dependencies to their latest versions. Also, the minimum supported version of Visual Studio is now 17.6 LTSC (Roslyn 4.4).
Additionally, we must declare a few breaking changes in the public API of IRef
and Metalama.Patterns.Commands
. For details, see the release notes
Conclusion
Metalama 2025.0 is a great release from several angles. Not only is this a platform update release, but it also closes most feature gaps in the aspect framework and brings impressive performance improvements.
Note that implementing these improvements required extensive refactoring of the code model. As a result, we may have destabilized some use cases that were not covered by any tests. Please be careful when updating to 2025.0 (i.e., don’t do it in a rush), and don’t hesitate to report any issues.
We’re looking forward to your feedback.
Happy meta-programming with Metalama!