| Severity | Error |
| Reported by | PostSharp |
| Message | The project language "<Language>" is not supported. PostSharp supports only C# and Visual Basic projects. |
Cause
PostSharp supports C# and Visual Basic projects. It reads the language of the project from the Language MSBuild property, which the SDK of the language sets, and uses it to understand the code that the compiler generates: the backing fields of automatic properties, and the classes of iterators and async methods.
When the language is neither C# nor VB, for example in an F# project, PostSharp still starts, but reports PS0214, a fatal error, as soon as it needs one of these details, for example when it weaves an aspect on an async method. <Language> is the value of the Language property, or is empty when the project does not set it.
In the following example, the @Property(Language=F#) directive of the test framework simulates an F# project, and the [Log] aspect is applied to an async method.
// @Property(Language=F#)
using System;
using System.Threading.Tasks;
using PostSharp.Aspects;
using PostSharp.Serialization;
namespace Errors.PS0214_Error;
[PSerializable]
public class LogAttribute : OnMethodBoundaryAspect
{
public override void OnEntry( MethodExecutionArgs args )
{
Console.WriteLine( $"Entering {args.Method.Name}." );
}
public override void OnExit( MethodExecutionArgs args )
{
Console.WriteLine( $"Leaving {args.Method.Name}." );
}
}
public class OrderService
{
// PostSharp must know how the compiler of the project generates async state machines to weave this method.
[Log]
public async Task PlaceOrderAsync( string product )
{
await Task.Delay( 10 );
Console.WriteLine( $"Order placed for {product}." );
}
}
public static class Program
{
public static async Task Main()
{
await new OrderService().PlaceOrderAsync( "Coffee" );
}
}
error PS0214: The project language "F#" is not supported. PostSharp supports only C# and Visual Basic projects.
Resolution
- Move the code that needs aspects to a C# or Visual Basic project, and reference this project from the project in the other language.
- When the project is a C# or Visual Basic project, make sure that nothing overrides the
LanguageMSBuild property, for example a custom.targetsfile or thePostSharpPropertiesproperty.
In the following example, the language of the project is C#, and the aspect is woven into the async method.
// @Property(Language=C#)
using System;
using System.Threading.Tasks;
using PostSharp.Aspects;
using PostSharp.Serialization;
namespace Errors.PS0214_Fixed;
[PSerializable]
public class LogAttribute : OnMethodBoundaryAspect
{
public override void OnEntry( MethodExecutionArgs args )
{
Console.WriteLine( $"Entering {args.Method.Name}." );
}
public override void OnExit( MethodExecutionArgs args )
{
Console.WriteLine( $"Leaving {args.Method.Name}." );
}
}
public class OrderService
{
// The project language is C#, whose async state machines PostSharp knows how to weave.
[Log]
public async Task PlaceOrderAsync( string product )
{
await Task.Delay( 10 );
Console.WriteLine( $"Order placed for {product}." );
}
}
public static class Program
{
public static async Task Main()
{
await new OrderService().PlaceOrderAsync( "Coffee" );
}
}
Entering PlaceOrderAsync.
Order placed for Coffee.
Leaving PlaceOrderAsync.
See Also
Reference
Other Resources
Requirements and Compatibility
Well-Known MSBuild Properties