| Severity | Error |
| Reported by | PostSharp |
| Message | Invalid property name "<PropertyName>": the name of a property must start with a letter and contain only letters and digits. |
Cause
The Property element of a postsharp.config file defines a property of the project, which other elements read in expressions such as {$LoggingEnabled}. See Configuration File Schema Reference. Because expressions refer to properties by name, the name of a property must start with a letter and contain only letters and digits. A hyphen, a dot, an underscore or a space makes it invalid. Spaces before and after the name are ignored.
PostSharp reports PS0204 on the Property element, and ignores the property. Since the error occurs while PostSharp loads the configuration of the project, it also reports PS0084 and stops the build.
In the following example, the name of the property contains a hyphen.
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.postsharp.org/1.0/configuration">
<!-- The name of a property cannot contain a hyphen. -->
<Property Name="Logging-Enabled" Value="True" />
</Project>
using System;
using PostSharp.Aspects;
using PostSharp.Serialization;
namespace Errors.PS0204_Error;
[PSerializable]
public class LogAttribute : OnMethodBoundaryAspect
{
public override void OnEntry( MethodExecutionArgs args )
{
Console.WriteLine( $"Entering {args.Method.Name}." );
}
}
public class OrderService
{
[Log]
public void PlaceOrder( string product )
{
Console.WriteLine( $"Order placed for {product}." );
}
}
public static class Program
{
public static void Main()
{
new OrderService().PlaceOrder( "Coffee" );
}
}
error PS0084: The project could not be initialized because of the previous errors.
error PS0204: postsharp.config(4,4): Invalid property name "Logging-Enabled": the name of a property must start with a letter and contain only letters and digits.
Resolution
Rename the property so that its name contains only letters and digits, and update the expressions that refer to it.
In the following example, the property is named LoggingEnabled.
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.postsharp.org/1.0/configuration">
<!-- The name of the property contains only letters and digits. -->
<Property Name="LoggingEnabled" Value="True" />
</Project>
using System;
using PostSharp.Aspects;
using PostSharp.Serialization;
namespace Errors.PS0204_Fixed;
[PSerializable]
public class LogAttribute : OnMethodBoundaryAspect
{
public override void OnEntry( MethodExecutionArgs args )
{
Console.WriteLine( $"Entering {args.Method.Name}." );
}
}
public class OrderService
{
[Log]
public void PlaceOrder( string product )
{
Console.WriteLine( $"Order placed for {product}." );
}
}
public static class Program
{
public static void Main()
{
new OrderService().PlaceOrder( "Coffee" );
}
}
Entering PlaceOrder.
Order placed for Coffee.
See Also
Other Resources
Configuration File Schema Reference
Using Expressions in Configuration Files
Configuring Projects Using postsharp.config