Table of Contents

NBMsgPack061: UnusedDataPacket member should not have a KeyAttribute

When used within a class, KeyAttribute must be applied on every serializable property and field. Learn more about this in the NBMsgPack001 diagnostic documentation.

Properties and fields typed as UnusedDataPacket are specially serialized properties and have no designated position in an array. Learn more about this in the retaining unrecognized data documentation. As such, KeyAttribute should not be applied to these properties.

Example violation

public class Person
{
    [Key(0)]
    public required string Name { get; set; }

    [Key(1)] // NBMsgPack061
    [PropertyShape]
    private UnusedDataPacket Extension { get; set; }
}

Resolution

Drop the KeyAttribute from the UnusedDataPacket property.

public class Person
{
    [Key(0)]
    public required string Name { get; set; }

    [PropertyShape]
    private UnusedDataPacket Extension { get; set; }
}