| Severity | Error |
| Reported by | PostSharp |
| Message | Invalid attribute "<AttributeName>" on the element "<ElementName>": only the Condition attribute can be in the namespace of the PostSharp configuration schema. |
Cause
Some elements of a postsharp.config file describe CLR objects in XML: the children of the Multicast element, which add aspects to the project, and the content of the Logging element. Each XML attribute of such an element, without a namespace prefix, sets the field or property of the same name. See Including CLR Objects in Configuration.
The only attribute that can be in the namespace of the PostSharp configuration schema, http://schemas.postsharp.org/1.0/configuration, is Condition, often written x:Condition, which PostSharp evaluates instead of passing it to the object. PostSharp reports PS0206 on any other attribute in this namespace, and ignores the element. <ElementName> is the name of the element with its XML namespace in braces.
In the following example, the AttributeTargetTypes attribute has the x prefix, which maps to the namespace of the configuration schema.
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.postsharp.org/1.0/configuration" xmlns:x="http://schemas.postsharp.org/1.0/configuration">
<Multicast xmlns:app="clr-namespace:Errors.PS0206_Error;assembly:PS0206_Error">
<!-- Only the Condition attribute can be in the namespace of the configuration schema. -->
<app:LogAttribute x:AttributeTargetTypes="Errors.PS0206_Error.OrderService" AttributeTargetMembers="PlaceOrder" />
</Multicast>
</Project>
using System;
using PostSharp.Aspects;
using PostSharp.Serialization;
namespace Errors.PS0206_Error;
// The postsharp.config file applies this aspect to OrderService.
[PSerializable]
public class LogAttribute : OnMethodBoundaryAspect
{
public override void OnEntry( MethodExecutionArgs args )
{
Console.WriteLine( $"Entering {args.Method.Name}." );
}
}
public class OrderService
{
public void PlaceOrder( string product )
{
Console.WriteLine( $"Order placed for {product}." );
}
}
public static class Program
{
public static void Main()
{
new OrderService().PlaceOrder( "Coffee" );
}
}
error PS0206: postsharp.config(5,23): Invalid attribute "AttributeTargetTypes" on the element "{clr-namespace:Errors.PS0206_Error;assembly:PS0206_Error}LogAttribute": only the Condition attribute can be in the namespace of the PostSharp configuration schema.
Resolution
Remove the namespace prefix of the attributes that set a field or a property of the object. Keep the prefix only on Condition, or write Condition without prefix.
In the following example, AttributeTargetTypes has no prefix, and the aspect is applied.
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.postsharp.org/1.0/configuration" xmlns:x="http://schemas.postsharp.org/1.0/configuration">
<Multicast xmlns:app="clr-namespace:Errors.PS0206_Fixed;assembly:PS0206_Fixed">
<!-- The attribute that sets a property of the aspect has no namespace prefix. -->
<app:LogAttribute AttributeTargetTypes="Errors.PS0206_Fixed.OrderService" AttributeTargetMembers="PlaceOrder" />
</Multicast>
</Project>
using System;
using PostSharp.Aspects;
using PostSharp.Serialization;
namespace Errors.PS0206_Fixed;
// The postsharp.config file applies this aspect to OrderService.
[PSerializable]
public class LogAttribute : OnMethodBoundaryAspect
{
public override void OnEntry( MethodExecutionArgs args )
{
Console.WriteLine( $"Entering {args.Method.Name}." );
}
}
public class OrderService
{
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
Including CLR Objects in Configuration
Adding Aspects Using XML
Configuration File Schema Reference