MetalamaConceptual documentationMigrating from Post­SharpWhen migrate
Open sandboxFocusImprove this doc

When to migrate from PostSharp to Metalama

Warning

Migrating your existing projects from PostSharp to Metalama currently may not be the best option. This decision should be thoroughly considered.

Before deciding to migrate your code from PostSharp to Metalama, it's crucial to evaluate whether it's the right time to do so. Given that PostSharp will continue to be maintained for several more years, there may not be an immediate need to switch to Metalama.

Avoid mixing PostSharp and Metalama in the same project

While it's theoretically possible to use both PostSharp and Metalama in the same project, it's not recommended due to the following reasons:

  • Both Metalama and PostSharp introduce helper methods and properties—methods without an equivalent in the source code. Since PostSharp operates after Metalama, it will recognize these helper declarations and the aspects will treat them as user code, potentially causing confusion and errors.
  • All Metalama aspects will be applied before any PostSharp aspect, simply because Metalama operates before PostSharp. This constrains the order in which aspects can be applied.
  • We have not tested PostSharp and Metalama together and will not investigate or resolve issues that may arise from their combined use. In other words, this scenario is not supported.

Migrating is not an all-or-nothing decision

Teams or companies can use both PostSharp and Metalama concurrently. There's no need for a company-wide decision to initiate the migration.

You can continue using PostSharp for one product while migrating to Metalama for another. This approach may be viable as long as these products don't have dependencies that would result in a single C# project utilizing both Metalama and PostSharp.

When to migrate to Metalama

Consider migrating to Metalama if:

  • Your project is dependent on a platform that will not support PostSharp (for instance, an ARM64 build environment or WinUI projects), or
  • The benefits outweigh the effort required for migration. For more details, refer to Benefits of Metalama over PostSharp.

DO NOT migrate to Metalama at this time if:

  • Your project depends on a platform that is supported by PostSharp but not by Metalama (for example, a pre-2020 platform):

    • Visual Studio 2019 or earlier
    • .NET Standard 1.6 or earlier
    • .NET Framework 4.6 or earlier
    • Visual Basic (Metalama is available for C# projects only)
  • Your project depends on PostSharp features that have not yet been ported to Metalama. For more details, refer to Status of the migration of PostSharp features to Metalama.

  • Your company has a large team working on a business-critical project with a tight deadline and prefers the tried-and-tested PostSharp (2008) over the relatively new Metalama (2023).