Skip to content

PostSharp 2027.0.3-preview

Pre-release
Pre-release

Choose a tag to compare

@gfraiteur gfraiteur released this 08 Oct 04:19

PostSharp 2027.0.3-preview is based on v2027.0.2-preview, plus the following changes.

New

  • PostSharp.AI.Skills: a PostSharp plugin for Claude Code and OpenAI Codex. It gives coding agents the PostSharp documentation and API reference, so that they write PostSharp code from the real API instead of guessing.

Advice Parameter Binding

This preview continues the work on advice parameter binding, which became a public feature in 2027.0.2-preview (#168).

  • #164 The new [Exception] binding gives the exception to an [OnMethodExceptionAdvice] with bound parameters. A ref or out parameter can replace the exception, and FlowBehavior.ThrowException now throws it. Before, a bound advice rethrew the original exception.
  • #165 [ReturnValue] is now accepted in method boundary advices. Success and exit advices can read the return value and replace it. Entry and exception advices can set the value that FlowBehavior.Return returns. In an async method, the value is the result of the task.
  • #166 The new [Declaration] binding gives the reflection object of the target: the MethodBase of a method (the method declared in source code for an async method or an iterator), the LocationInfo of a field or property, or the Type of a constructed instance.
  • #163 The compiler now checks each binding against the advice kinds, parameter modes and counts it accepts. Combinations that crashed the compiler or produced invalid IL are now errors, and those that had no effect are now warnings.
  • #169 The type arguments of generic advice methods are now inferred correctly, including for by-reference parameters, constraints between type parameters and generic aspect classes. LA0220 now gives the reason, and the new warning LA0245 reports an unused type parameter.
  • #238 [CurrentTask] is now null until the async method has yielded; on .NET, the task read earlier never completed. After the first yield, it is the task of the caller. ValueTask and ValueTask<T> are now supported. ⚠️ Breaking change.
  • #243 Fixed an internal compiler exception when an advice under MatchPointcut binds an argument by name ([Argument("x")]) or by type ([Argument]).

Enhancements

  • #92 The MSBuild integration now works in the MSBuild server, which the .NET 11 SDK enables by default. The cache of installed .NET runtimes is refreshed when the installation changes, and the memory throttling no longer shuts down the MSBuild server that runs the build.
  • #240 PostSharpValidateLanguageVersion no longer loads the Roslyn assemblies of the SDK into the MSBuild process, where they stayed loaded and locked.

⚠️ Breaking Changes

  • #201 TreatWarningsAsErrors now applies to the warnings of PostSharp and of aspects, through the new PostSharpTreatWarningsAsErrors property, which honors WarningsNotAsErrors. Set it to False for the previous behavior. The PostSharp codes in WarningsAsErrors are escalated too.
  • #205 Implementing an [InternalImplement] interface of PostSharp.dll, such as IArgumentsWriter, is now reported as warning AR0101.
  • #206 Applying an [Internal] custom attribute of another assembly is now reported as warning AR0105.
  • #237 [Internal] read [InternalsVisibleTo] in the wrong direction. A friend assembly of the declaring assembly no longer gets AR0105. An assembly that only grants the declaring assembly access to its own internals now gets AR0105.
  • #225 PostSharp.Patterns.Diagnostics.Serilog now depends on Serilog 4.4.0 instead of 2.3.0. An application that uses Serilog 2.x or 3.x is upgraded, and sinks built for Serilog 2 may need a newer version.
  • #221 The Serilog backend no longer passes string values with PostSharp's quotes, for example guest instead of "guest". Sinks that read the properties receive the new value. Serilog adds its own quotes in the rendered message.

Fixes

MSBuild integration and packaging

  • #156 Fixed a build failure when the .NET 11 CLI cannot connect to the MSBuild server during the restore of the compiler dependencies. The restore is now judged by its exit code, not by its standard error.
  • #241 PostSharpExtractTools could extract the compiler of another package with the same main version. The archive is now taken from the imported package, and a warning is reported when the task assembly that runs is not the one the project imports.
  • #193 Mismatched versions of PostSharp and PostSharp.Redist are now diagnosed. A higher PostSharp.Redist is an error that gives the dotnet nuget why command, which shows the package that requires it. A lower one is a warning. PostSharpRedistVersionCheckDisabled skips the check.
  • #197 Fixed a build failure when the project targets a Windows SDK version that is newer than the Windows version of the build machine.
  • #198 The reference packs of the target frameworks of referenced assemblies, such as NETStandard.Library.Ref, are now restored when the SDK does not include them.

Compiler output

  • #194 PostSharp no longer removes the public signing flag (<PublicSign>true</PublicSign>) of the assembly.
  • #195 The debug directory of an assembly with a Windows PDB no longer says that the PDB is a Portable PDB. This broke tools such as dotCover.
  • #196 The local variables of a method enhanced by an aspect are now visible in the debugger on the closing brace.
  • #199 Fixed a BindingException when PostSharp builds a facade assembly for Microsoft.VisualStudio.Debugger.Engine.dll.

Aspect ordering

  • #203 AspectDependencyAction.Commute is now taken into account when only one of the two aspects declares it.
  • #204 PS0114 no longer reports an aspect as conflicting with itself on async methods and iterators.

Threading models

  • #207 An abstract event in a [ReaderWriterSynchronized] class no longer fails with LA0146.
  • #208 The thread-safety policy now recognizes the thread-safe types of referenced assemblies.
  • #211 The LockRecursionException thrown when a [Writer] method is called from a [Yielder] method now explains the cause, and recommends [UpgradeableReader] on the method that raises the event.
  • #212 Fixed a lock that was acquired on each access to a thread-safe object after its parent had changed.
  • #213 The enumerators of advisable collections no longer throw after an await that resumes on another thread. The threading model decides: [ThreadAffine] throws ThreadMismatchException, and [Synchronized] and [ReaderWriterSynchronized] take the lock.

NotifyPropertyChanged

  • #214 [NotifyPropertyChanged] no longer keeps the parent alive through its subscription to a child that implements INotifyPropertyChanged by hand.
  • #215 [NotifyPropertyChanged] no longer throws NullReferenceException for an explicitly implemented auto-property.
  • #226, #229, #230, #234 Fixed [NotifyPropertyChanged] defects that caused missing, duplicate or early notifications, and stale subscriptions. Dependencies declared with Depends.On on another property are now tracked.
  • #227 NotifyPropertyChangedServices.ResumeEvents without a matching SuspendEvents now throws InvalidOperationException instead of silently disabling the next suspension.
  • #228 NotifyPropertyChangedOverflowException is now thrown for an infinite loop of notifications, and no longer for a flush that ends normally after 64 passes.
  • #232 Fixed an infinite loop in WeakEventHandler.Remove when another thread changes the handlers at the same time.
  • #235 Fixed a race condition that could drop a ChildPropertyChanged notification when types are initialized on several threads.
  • #233 The messages DOM002, DOM003 and DOM023 no longer tell you to put [SafeForDependencyAnalysis] on a method.

Contracts

  • #218 [StrictlyLessThan], [StrictlyGreaterThan] and [StrictRange] no longer reject values that are near their bound but within it, and the error message of [StrictlyLessThan] is now defined.

Logging

  • #220 The Serilog backend no longer fails with Serilog 3.0 and later.
  • #222 The Serilog backend now includes the type name in custom messages.

SharpCrafters.Backstage

  • SharpCrafters.Backstage#23 Fixed a process crash with ObjectDisposedException when the registry change watcher is disposed while its callback is running.

Enhancements of v2024.0.28

These enhancements of v2024.0.28, which is not released yet, are also included in this preview.

  • #177 When an assembly fails to load because of an earlier request made before the project was loaded, PS0265 now shows the complete stack trace of the code that made that request, and the assembly resolution logs the requesting assembly.
  • #176 The new FileLock trace category (PostSharpTrace=FileLock) records the retries of file operations that fail because the file is locked. In this preview, it does not yet record the retries themselves, which need a later version of SharpCrafters.Backstage.
  • #178 The POSTSHARP_FILE_LOCK_TIMEOUT and POSTSHARP_FILE_LOCK_WARNING environment variables set the timeout and the warning threshold of the retries on locked files, in milliseconds. They have no effect in this preview, because they need a later version of SharpCrafters.Backstage.

Resources