| Severity | Error |
| Reported by | PostSharp |
| Message | Invalid value for AspectRoleDependencyAttribute: the "role" parameter value cannot be null or empty. |
Cause
The AspectRoleDependencyAttribute custom attribute declares a dependency between the aspect that it is applied to and the aspects or advices of a role, such as ordering them or forbidding them on the same target. The dependency matches the aspects and advices that are enrolled in the role with ProvideAspectRoleAttribute, by its name. A dependency without a name matches nothing, so PostSharp reports LA0148 when the role argument is null or an empty string.
PostSharp reports the message without a location, and the message does not name the aspect. Look for an AspectRoleDependencyAttribute whose role is empty, or comes from a constant or an expression that is empty, on the aspects that the project uses.
In the following example, the [Log] aspect declares a dependency with an empty role.
using System;
using PostSharp.Aspects;
using PostSharp.Aspects.Dependencies;
using PostSharp.Serialization;
namespace Errors.LA0148_Error;
[PSerializable]
[ProvideAspectRole( StandardRoles.Caching )]
public class CacheAttribute : OnMethodBoundaryAspect
{
public override void OnEntry( MethodExecutionArgs args ) => Console.WriteLine( "Looking up the cache." );
}
[PSerializable]
// The role of the dependency is empty.
[AspectRoleDependency( AspectDependencyAction.Order, AspectDependencyPosition.Before, "" )]
public class LogAttribute : OnMethodBoundaryAspect
{
public override void OnEntry( MethodExecutionArgs args ) => Console.WriteLine( $"Entering {args.Method.Name}." );
}
public class ProductCatalog
{
[Log]
[Cache]
public decimal GetPrice( string product ) => 12.5m;
}
public static class Program
{
public static void Main()
{
Console.WriteLine( new ProductCatalog().GetPrice( "Book" ) );
}
}
error LA0148: Invalid value for AspectRoleDependencyAttribute: the "role" parameter value cannot be null or empty.
Resolution
Pass the name of a role to the attribute, preferably a constant of StandardRoles, or the role that the other aspect declares with ProvideAspectRoleAttribute. If the aspect does not depend on any role, remove the attribute.
In the following example, the [Log] aspect runs before the aspects of the caching role.
using System;
using PostSharp.Aspects;
using PostSharp.Aspects.Dependencies;
using PostSharp.Serialization;
namespace Errors.LA0148_Fixed;
[PSerializable]
[ProvideAspectRole( StandardRoles.Caching )]
public class CacheAttribute : OnMethodBoundaryAspect
{
public override void OnEntry( MethodExecutionArgs args ) => Console.WriteLine( "Looking up the cache." );
}
[PSerializable]
// The dependency names the role of the caching aspect.
[AspectRoleDependency( AspectDependencyAction.Order, AspectDependencyPosition.Before, StandardRoles.Caching )]
public class LogAttribute : OnMethodBoundaryAspect
{
public override void OnEntry( MethodExecutionArgs args ) => Console.WriteLine( $"Entering {args.Method.Name}." );
}
public class ProductCatalog
{
[Log]
[Cache]
public decimal GetPrice( string product ) => 12.5m;
}
public static class Program
{
public static void Main()
{
Console.WriteLine( new ProductCatalog().GetPrice( "Book" ) );
}
}
Entering GetPrice.
Looking up the cache.
12.5
See Also
Reference
AspectRoleDependencyAttribute
ProvideAspectRoleAttribute
StandardRoles
Other Resources