| Severity | Error |
| Reported by | PostSharp |
| Message | The advices <Advices> are in one group and set <Property> to different values, but <Property> applies to the whole group. Set it on one advice of the group only. |
Cause
Some properties of the advices apply to the whole group of advices: the pointcut, Description, SemanticallyAdvisedMethodKinds and UnsupportedTargetAction. A group has one value of each, so you can set them on any advice of the group, but on one advice only.
PostSharp reports LA0231 on each advice of the conflict when two advices of one group set one of these properties to different values. The same value on several advices is accepted. When two advices of one group have a pointcut, PostSharp reports LA0259 instead.
<Advices> lists the advices that set the property, and <Property> names it.
In the following example, the entry advice and the exit advice of the aspect are in one group, and set Description to different texts.
using System;
using PostSharp.Aspects;
using PostSharp.Aspects.Advices;
using PostSharp.Serialization;
namespace Errors.LA0231_Error;
[PSerializable]
public class TraceAttribute : MethodLevelAspect
{
// Both advices of the group set Description, which applies to the whole group, to different values.
[OnMethodEntryAdvice( Description = "Writes a line when the method starts." )]
public void OnEntry()
{
Console.WriteLine( "Entering." );
}
[OnMethodExitAdvice( Description = "Writes a line when the method completes." )]
public void OnExit()
{
Console.WriteLine( "Leaving." );
}
}
public class OrderService
{
[Trace]
public void PlaceOrder( string product )
{
Console.WriteLine( $"Ordered {product}." );
}
}
public static class Program
{
public static void Main()
{
new OrderService().PlaceOrder( "Coffee" );
}
}
error LA0231: LA0231_Error.cs(13,17): The advices "Errors.LA0231_Error.TraceAttribute.OnEntry", "Errors.LA0231_Error.TraceAttribute.OnExit" are in one group and set Description to different values, but Description applies to the whole group. Set it on one advice of the group only.
error LA0231: LA0231_Error.cs(19,17): The advices "Errors.LA0231_Error.TraceAttribute.OnEntry", "Errors.LA0231_Error.TraceAttribute.OnExit" are in one group and set Description to different values, but Description applies to the whole group. Set it on one advice of the group only.
Resolution
Set the property on one advice of the group only, with a value that fits the whole group, or set the same value on each advice. When the advices must have different values, put them in different groups with the Group property or with pointcuts.
In the following example, only the entry advice sets Description, with a text that describes the whole group.
using System;
using PostSharp.Aspects;
using PostSharp.Aspects.Advices;
using PostSharp.Serialization;
namespace Errors.LA0231_Fixed;
[PSerializable]
public class TraceAttribute : MethodLevelAspect
{
// Only one advice sets Description, which describes the whole group.
[OnMethodEntryAdvice( Description = "Writes a line when the method starts and completes." )]
public void OnEntry()
{
Console.WriteLine( "Entering." );
}
[OnMethodExitAdvice]
public void OnExit()
{
Console.WriteLine( "Leaving." );
}
}
public class OrderService
{
[Trace]
public void PlaceOrder( string product )
{
Console.WriteLine( $"Ordered {product}." );
}
}
public static class Program
{
public static void Main()
{
new OrderService().PlaceOrder( "Coffee" );
}
}
Entering.
Ordered Coffee.
Leaving.
See Also
Reference
Description
OnMethodBoundaryAdvice
Group
Other Resources