Open sandboxFocusImprove this doc

COM013: Relationship Attribute in a Class Without the Aggregatable Aspect

Severity Warning
Reported by PostSharp.Patterns.Aggregation
Message The [<Attribute>] attribute applied to "<Member>" is ignored because the type <DeclaringType> does not have the [Aggregatable] aspect. Add the [Aggregatable] aspect to <DeclaringType>, or remove the attribute.

Cause

The ChildAttribute, ParentAttribute and ReferenceAttribute attributes describe the relationships of an object model, and only the AggregatableAttribute aspect reads them. The threading models, such as ThreadUnsafeAttribute, add this aspect to their target class too. When none of these aspects is applied to the class that declares the field or the property, PostSharp reports COM013 once it has discovered all the aspects of the project, and the attribute has no effect: the object assigned to a [Child] property does not get a parent, for example.

<Attribute> is the type of the attribute. The current version of the message shows its full name, such as PostSharp.Patterns.Model.ChildAttribute.

In the following example, the Line property of Order is annotated with [Child], but Order does not have the [Aggregatable] aspect, so the order line has no parent.

using System;
using PostSharp;
using PostSharp.Patterns.Model;

namespace Errors.COM013_Error;

public class Order
{
    // Order has no [Aggregatable] aspect, so [Child] has no effect.
    [Child] public OrderLine? Line { get; set; }
}

[Aggregatable]
public class OrderLine
{
    public string Product { get; set; } = "Keyboard";
}

public static class Program
{
    public static void Main()
    {
        Order order = new Order { Line = new OrderLine() };

        object? parent = Post.Cast<OrderLine, IAggregatable>( order.Line ).Parent;
        Console.WriteLine( $"Parent of the order line: {parent ?? "none"}" );
    }
}
warning COM013: COM013_Error.cs(10,31): The [PostSharp.Patterns.Model.ChildAttribute] attribute applied to "Errors.COM013_Error.Order.Line" is ignored because the type Errors.COM013_Error.Order does not have the [Aggregatable] aspect. Add the [Aggregatable] aspect to Errors.COM013_Error.Order, or remove the attribute.
Parent of the order line: none

Resolution

  • Add the [Aggregatable] aspect, or a threading model, to the class that declares the member.
  • If the class is not part of an object model, remove the attribute.

In the following example, Order has the [Aggregatable] aspect, so it becomes the parent of its line.

using System;
using PostSharp;
using PostSharp.Patterns.Model;

namespace Errors.COM013_Fixed;

// The [Aggregatable] aspect makes the order the parent of its child line.
[Aggregatable]
public class Order
{
    [Child] public OrderLine? Line { get; set; }
}

[Aggregatable]
public class OrderLine
{
    public string Product { get; set; } = "Keyboard";
}

public static class Program
{
    public static void Main()
    {
        Order order = new Order { Line = new OrderLine() };

        object? parent = Post.Cast<OrderLine, IAggregatable>( order.Line ).Parent;
        Console.WriteLine( $"Parent of the order line: {parent ?? "none"}" );
    }
}
Parent of the order line: Errors.COM013_Fixed.Order

See Also

Reference

AggregatableAttribute
ChildAttribute
ParentAttribute
ReferenceAttribute

Other Resources

Annotating an Object Model for Parent/Child Relationships (Aggregatable)