We've designed the PostSharp Licensing component so that it stands in your way as little as possible. However, there are legitimate cases in which we had to make the choice to prevent the build of your project. This article mentions these cases and gives solutions to such situations.
In case the solution given by this article doesn't work, or your case isn't listed, please contact our support.
This article only talks about the technical issues you may encounter. You can find more answers to your questions about PostSharp licensing in our licensing FAQ.
Understanding typical error messages and situations
Error PS0242: License error. No valid license key has been installed.
In case you do have a license key installed as mentioned in the Deploying License Keys and you're still getting this error, it most probably means that the version of PostSharp you are using has been released after the end of your subscription period. In this case, you either need to renew your subscription or to use an older version of PostSharp, that has been released before the end of your subscription period.
Error PS0243: License error. The project uses non-licensed premium features. It is not allowed to enhance types with a total of more than X lines of code in the project by features not covered by the installed licenses, but Y lines of code were enhanced.
There are two cases in which you might get such error:
You are using PostSharp Essentials license: In this case, you've hit the limitation of the license. To diagnose this, follow the information given at log.
You are using other license than PostSharp Essentials or PostSharp Ultimate license: If you don't have the unlimited PostSharp Ultimate license, any features not covered by your license are licensed as if you were using the PostSharp Essentials license. A quick way to figure out which features these are, is to look through all the namespace usings of namespaces
PostSharp.*. Another way is to follow the same information as for PostSharp Essentials as mentioned above.You are using PostSharp Diagnostics with a PostSharp Framework license in a version of PostSharp lower than 2025.1. The information that a PostSharp Framework licenses entitles for PostSharp Diagnostics is hard-coded in PostSharp, not in the license key. This is a new feature of PostSharp 2025.1. If you need to use your license key with an earlier version, please contact us.
A message warning that a license or subscription has expired pops up after installing a renewed license key
Uninstall the expired license key. See Deploying License Keys to figure out where the expired license key can be installed.
A license key fails to uninstall
There are various reasons for such behavior. A quick way to resolve this is to remove the LicenseCache and LicenseKeys registry keys from the following parent keys from Windows registry.
Computer\HKEY_CURRENT_USER\SOFTWARE\SharpCraftersComputer\HKEY_LOCAL_MACHINE\SOFTWARE\SharpCraftersComputer\HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\SharpCrafters
A redistribution license doesn't allow to build a project, although it only contains code that belongs the licensed namespace.
Besides the namespace, the assembly name must also match the licensed namespace name. Make sure that the compiled assembly name starts with the licensed namespace.
For example, if your licensed namespace is MyOssLib, you assembly name must be also MyOssLib, or MyOssLib. followed by an arbitrary string.
PostSharp license server is closing connections unexpectedly.
Make sure that the PostSharp License Server runs on .NET Framework 4.7.2 or newer.
The license key is valid in Visual Studio but rejected at build time
The Visual Studio extension and the build-time compiler are separate components, and they may run different versions of PostSharp. The Visual Studio extension — especially older 6.x extensions — uses its own license validation logic. As a result, a key that the Visual Studio UI accepts may still be rejected by a newer build-time compiler.
License keys are stored in the Windows registry under HKEY_CURRENT_USER\SOFTWARE\SharpCrafters\PostSharp 3\LicenseKeys\<MinPostSharpVersion>\. The <MinPostSharpVersion> sub-key corresponds to the minimum PostSharp version the key was generated for (for example, 6.9.3). At build time all version sub-keys are enumerated, so the key is found regardless of which version sub-key it lives under.
If the build reports PS0242 ("No valid license key has been installed") even though the key is present in the registry, use the diagnostic logging steps below to determine whether the key is being found but failing to deserialize or validate.
Common causes include:
- a license binary format incompatibility between PostSharp versions (fixed in later releases);
- a subscription that has expired relative to the PostSharp build date;
- the pipe server caching a failed license validation from a previous build (see the next section).
Stale pipe server and cached license failures
To improve performance, PostSharp uses a persistent pipe server process (postsharp-x64-srv.exe) that stays running between builds. The pipe server's primary AppDomain holds a SharedUserLicenseManager that caches the license state.
Once a license key is loaded and validated — or fails validation — the result is cached for the lifetime of the pipe server process. If a license key fails validation, it is permanently removed from the in-memory license collection. Subsequent builds that reuse the same pipe server will therefore see no license installed, even after you correct the underlying problem.
If you suspect stale cached state, kill any running postsharp-x64-srv.exe processes before rebuilding, or set PostSharpUsePipeServer=False to bypass the pipe server entirely.
Capturing licensing diagnostic logs
When you need to understand why PostSharp rejects a license key, you can capture a detailed trace of the license loading and validation process.
The PostSharpTrace MSBuild property enables one or more trace categories. To get licensing-specific diagnostics, set it to Licensing. For the trace messages to actually appear in the build output, the build must run with the -v:diag (diagnostic) verbosity, because PostSharp emits the trace as MSBuild info messages.
Important
By default on x64, PostSharp runs the license loading and validation code inside a separate AppDomain hosted by a pipe server (PostSharpUsePipeServer=True). In that AppDomain the trace output is silently discarded, so you will not see the licensing trace. To get complete licensing output, you must disable the pipe server by setting PostSharpUsePipeServer=False.
Warning
Do not combine PostSharpTrace="*" with PostSharpUsePipeServer=False. The wildcard category is not supported by the command-line parser and will crash PostSharp with a TypeInitializationException. Always specify an explicit category such as Licensing.
The following examples write the full trace to a trace.log file.
Using MSBuild:
msbuild -p:PostSharpTrace="Licensing" -p:PostSharpUsePipeServer=False -t:rebuild -v:diag MyProject.csproj > trace.log 2>&1
Using the .NET CLI:
dotnet build -p:PostSharpTrace="Licensing" -p:PostSharpUsePipeServer=False --no-incremental -v:diag MyProject.csproj > trace.log 2>&1
In the resulting log, look for lines prefixed with POSTSHARP : info LICENSING:. These lines show the registry keys being loaded, the deserialization of each license, the validation results, and the requirement-satisfaction checks. Following this sequence tells you whether the license key is being found at all, and if so, whether it fails to deserialize or fails validation.
Passing the license key explicitly as a workaround
If a license key is installed in the registry but PostSharp doesn't find it (or fails to parse it), you can bypass the registry-based resolution entirely by passing the key directly through the PostSharpLicense MSBuild property. This is also a useful diagnostic step: it tells you whether the problem lies in reading the registry or in the license key itself.
Option A: Directory.Build.props at the solution root:
<Project>
<PropertyGroup>
<PostSharpLicense>YOUR-LICENSE-KEY-HERE</PostSharpLicense>
</PropertyGroup>
</Project>
Option B: postsharp.config at the solution root:
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.postsharp.org/1.0/configuration">
<License Value="YOUR-LICENSE-KEY-HERE" />
</Project>