Skip to content

PostSharp 2027.0.4-preview

Pre-release
Pre-release

Choose a tag to compare

@gfraiteur gfraiteur released this 14 Oct 16:30

PostSharp 2027.0.4-preview is based on v2027.0.3-preview and v2026.0.19, plus the following changes.

This release forward-ports v2026.0.19: 3 enhancements and 5 bug fixes.

New

  • #255 Applications that use PostSharp can now be published with ReadyToRun, trimmed, or compiled ahead of time (NativeAOT).
    • #89 The aspect framework: a woven application no longer fails when its aspects are initialized after trimming or NativeAOT compilation. The serializers that the weaver generates are now created without reflection, and PostSharp.dll is annotated for the trimmer.
    • #252 The pattern libraries (Common, Aggregation, Model, Threading, Diagnostics and Caching) now work in trimmed and NativeAOT applications.
    • #254 The new advice InstantiateTypeAdviceInstance lets an aspect request the native code of a closed generic type that it creates by reflection at run time. [Cache] and [Log] use it.

Enhancements

  • #40 The new MSBuild property PostSharpDependencyRestoreProperties sets MSBuild properties, such as NuGetAudit=false, in the projects that PostSharp generates to restore its compiler dependencies. It does not affect the build of your project.
  • #158 What the licensing, configuration and telemetry services log is now written to the build-time trace (PostSharpTrace), in the trace category of the same name. Before, it went to a separate log configured by diagnostics.json.
  • #190 An unattended build is now licensed for PostSharp Logging in production mode.
  • #242 The MethodBase of a generic method, or of a method of a generic type, is now looked up once per generic instance instead of on each call.
  • #266 The FileLock trace category now records the retries of file operations that fail because the file is locked, and the POSTSHARP_FILE_LOCK_TIMEOUT and POSTSHARP_FILE_LOCK_WARNING environment variables now set the timeout and the warning threshold of these retries. 2027.0.3-preview introduced them, but they had no effect until this version.
  • #239 The XML documentation of MethodPointcut, MatchPointcut and the instance lifecycle advices now describes which targets they accept.

Fixes

Aspect framework

  • #189 With runtime async, an exception thrown by an OnYield or OnResume advice no longer runs the finally blocks of the user code around the await, so runtime async now behaves as a compiler state machine. With the new MSBuild property PostSharpCompatibilityLevel set to 2027.0 or higher, the exception instead goes through the catch and finally blocks of the user code, then through OnException and OnExit, with both implementations. ⚠️ Breaking change.
  • #244 An advice that joins a group implicitly and sets SemanticallyAdvisedMethodKinds, UnsupportedTargetAction or ApplyToStateMachine, which only the master advice can set, is now reported as error LA0135. Before, the value was ignored without any message.
  • #263 A method interception advice applied to an abstract method is now reported as warning LA0254. The behavior is unchanged: neither the abstract method nor its overrides are intercepted.
  • #258, #259 MatchPointcut on a method-level or an assembly-level aspect is now reported as error LA0251, instead of failing the build with an InvalidCastException.
  • #249 An InvalidAnnotationException thrown by CompileTimeValidate is now reported as error LA0252 at the target, with the message of the exception, instead of as the unexpected exception PS0125.
  • #250 An aspect applied to a C# 14 extension property is now applied to its accessors. Before, it was ignored without any message.
  • #251 The PS0112 message of a positioned Require or Conflict dependency now states the order correctly, and the documentation of AspectDependencyAction now describes the position of the current aspect. Which builds fail is unchanged.
  • #264 [WaiveAspectEffect] is now taken into account on aspects that use advice methods.
  • #256 A generic [ReturnValue] out T parameter of an invoke advice applied to a void method no longer causes a BadImageFormatException: the advice receives no return value. A non-generic [ReturnValue] out object parameter in the same situation now builds too; set IsRequired = true to keep an error.
  • #257 A by-value [LocationValue] object parameter of a set advice on a property of a value type is now boxed, instead of producing invalid IL.
  • #260 An OnMethodInvokeAdvice with bound parameters applied to an instance method of a struct no longer fails the build with a NullReferenceException.

Compiler and packaging

  • #265 On Linux and macOS, warning PS0134 for a Windows-format PDB now says that this format can be read on Windows only, instead of giving a meaningless reason.
  • #268 On Linux, the weaver of a pattern library is now found when the package version has capital letters, such as 2027.0.3-Beta1. Before, the build failed with PS0052.
  • #270 The unzipper of the PostSharp package now uses SharpCompress 0.49.0, which security scanners no longer report as vulnerable (GHSA-6c8g-7p36-r338). The vulnerability was not exploitable through PostSharp.

Licensing

  • #271 On Windows, a build with VcsCheckEnabled no longer waits two minutes and then requires a license although no source file is modified. The git command that checks the source files blocked on the standard input that it inherited from the compiler.

Pattern libraries

  • #112 A relationship attribute ([Child], [Parent], [Reference]) or [ExplicitlySynchronized] applied with the field: target to an automatic property is now reported, with the new warnings COM015 to COM018 and THR042, instead of being ignored without any message. The new MSBuild property PostSharpUnifiedAutomaticPropertyAnnotations makes the attributes of a property and of its backing field be read as one set.
  • #267 The new warning THR043 reports an appliesToMethodOnly argument of [ExplicitlySynchronized] that has no effect because the attribute is applied to a property. The behavior is unchanged.
  • #247 A property that depends on an [AggregateAllChanges] collection now raises PropertyChanged once, not twice, when an item is added.
  • #248 Closing a logging activity twice is now reported to ILoggingExceptionHandler.OnInvalidUserCode, with a message that says that the activity is already closed. Before, it was reported as an internal exception, and the default handler disabled the backend.

Resources