Open sandboxFocusImprove this doc

PS0275: Unsupported Target Platform

Severity Fatal error
Reported by PostSharp
Message The project targets or references an unsupported platform: <Framework>.

Cause

PostSharp must know the platform of the project and of each referenced assembly to find their framework assemblies. It reads the platform from the TargetFrameworkMoniker of the project and from the TargetFrameworkAttribute of each referenced assembly, and supports the following framework identifiers: .NETFramework, .NETCoreApp (.NET Core and .NET 5 or later), .NETStandard, .NETCore (UWP and Windows Runtime), .NETPortable, MonoAndroid, MonoTouch and Xamarin.iOS.

PostSharp reports PS0275 when the project or a referenced assembly names another framework, for example Silverlight, Windows Phone or the .NET Micro Framework. <Framework> is the framework name, with its version. The error is fatal: PostSharp stops processing the project.

In the following example, the project references a library whose assembly declares that it was built for Silverlight.

using System.Runtime.Versioning;

// The library declares that it was built for Silverlight, which PostSharp does not support.
[assembly: TargetFramework( "Silverlight,Version=v5.0" )]

namespace Errors.PS0275_Error.Pricing;

public static class PriceCalculator
{
    public static decimal ApplyDiscount( decimal price, decimal rate ) => price * (1 - rate);
}
// @DisabledMessages(PS0131)

using System;
using Errors.PS0275_Error.Pricing;

namespace Errors.PS0275_Error;

public static class Program
{
    public static void Main()
    {
        // PriceCalculator comes from a library built for Silverlight.
        Console.WriteLine( $"Discounted price: {PriceCalculator.ApplyDiscount( 100m, 0.2m ):0.00}" );
    }
}
error PS0275: The project targets or references an unsupported platform: Silverlight,Version=v5.0.

Resolution

  • When a referenced library is built for an unsupported platform, reference a build of this library for a supported platform, typically .NET Standard or .NET. Find the platform of a referenced assembly in its TargetFrameworkAttribute, for example with ILSpy.
  • When the project itself targets an unsupported platform, move the code that uses PostSharp to a .NET Standard library, and reference this library from the project. See Requirements and Compatibility for the platforms that PostSharp supports.

To see which framework PostSharp failed to recognize, and from which assembly it comes, enable the AssemblyBinder trace category with the PostSharpTrace MSBuild property (see Well-Known MSBuild Properties).

In the following example, the project references the .NET Standard build of the library.

using System.Runtime.Versioning;

// The library is built for .NET Standard, which PostSharp supports.
[assembly: TargetFramework( ".NETStandard,Version=v2.0" )]

namespace Errors.PS0275_Fixed.Pricing;

public static class PriceCalculator
{
    public static decimal ApplyDiscount( decimal price, decimal rate ) => price * (1 - rate);
}
// @DisabledMessages(PS0131)

using System;
using Errors.PS0275_Fixed.Pricing;

namespace Errors.PS0275_Fixed;

public static class Program
{
    public static void Main()
    {
        // PriceCalculator comes from the .NET Standard build of the library.
        Console.WriteLine( $"Discounted price: {PriceCalculator.ApplyDiscount( 100m, 0.2m ):0.00}" );
    }
}
Discounted price: 80.00

See Also

Other Resources

Requirements and Compatibility
target-frameworks
Well-Known MSBuild Properties