Open sandboxFocusImprove this doc

LA0115: Assembly-Level Aspect Dependency Without a Target Type

Severity Error
Reported by PostSharp
Message The aspect dependency "<Dependency>" applied to the assembly does not set the TargetType property. At assembly level, set TargetType to the aspect type to which the dependency applies.

Cause

An aspect dependency, such as AspectTypeDependencyAttribute or AspectRoleDependencyAttribute, usually decorates an aspect class, and it then applies to that aspect. You can also apply it to the assembly, to order or constrain aspects whose classes you cannot modify. At assembly level, there is no aspect class to attach the dependency to, so the TargetType property must name it. When this property is not set, PostSharp reports LA0115 and ignores the dependency.

The message does not point to a line, and <Dependency> is the kind of dependency (AspectDependency), not the name of the custom attribute: look for the aspect dependency attributes applied with [assembly: ...] in the project.

In the following example, an assembly-level dependency orders the [Log] aspect before the [Authorize] aspect, but it does not say that it applies to [Log].

using System;
using PostSharp.Aspects;
using PostSharp.Aspects.Dependencies;
using PostSharp.Serialization;

// The dependency is applied to the assembly, but it does not say to which aspect it applies.
[assembly: AspectTypeDependency( AspectDependencyAction.Order, AspectDependencyPosition.Before, typeof(Errors.LA0115_Error.AuthorizeAttribute) )]

namespace Errors.LA0115_Error;

[PSerializable]
public class LogAttribute : OnMethodBoundaryAspect
{
    public override void OnEntry( MethodExecutionArgs args ) => Console.WriteLine( $"Log: entering {args.Method.Name}." );
}

[PSerializable]
public class AuthorizeAttribute : OnMethodBoundaryAspect
{
    public override void OnEntry( MethodExecutionArgs args ) => Console.WriteLine( $"Authorize: checking {args.Method.Name}." );
}

public class OrderService
{
    [Log]
    [Authorize]
    public void CancelOrder( int orderId ) => Console.WriteLine( $"Order {orderId} canceled." );
}

public static class Program
{
    public static void Main()
    {
        new OrderService().CancelOrder( 42 );
    }
}
error LA0115: The aspect dependency "AspectDependency" applied to the assembly does not set the TargetType property. At assembly level, set TargetType to the aspect type to which the dependency applies.

Resolution

Set the TargetType property of the custom attribute to the aspect type to which the dependency applies. When you can modify the aspect class, you can instead move the custom attribute to that class, where TargetType is not needed.

In the following example, the dependency applies to [Log], which now runs before [Authorize].

using System;
using PostSharp.Aspects;
using PostSharp.Aspects.Dependencies;
using PostSharp.Serialization;

// The TargetType property names the aspect to which the dependency applies.
[assembly: AspectTypeDependency( AspectDependencyAction.Order, AspectDependencyPosition.Before, typeof(Errors.LA0115_Fixed.AuthorizeAttribute),
    TargetType = typeof(Errors.LA0115_Fixed.LogAttribute) )]

namespace Errors.LA0115_Fixed;

[PSerializable]
public class LogAttribute : OnMethodBoundaryAspect
{
    public override void OnEntry( MethodExecutionArgs args ) => Console.WriteLine( $"Log: entering {args.Method.Name}." );
}

[PSerializable]
public class AuthorizeAttribute : OnMethodBoundaryAspect
{
    public override void OnEntry( MethodExecutionArgs args ) => Console.WriteLine( $"Authorize: checking {args.Method.Name}." );
}

public class OrderService
{
    [Log]
    [Authorize]
    public void CancelOrder( int orderId ) => Console.WriteLine( $"Order {orderId} canceled." );
}

public static class Program
{
    public static void Main()
    {
        new OrderService().CancelOrder( 42 );
    }
}
Log: entering CancelOrder.
Authorize: checking CancelOrder.
Order 42 canceled.

See Also

Reference

AspectDependencyAttribute
AspectTypeDependencyAttribute
AspectRoleDependencyAttribute

Other Resources

Coping with Several Aspects on the Same Target