| Severity | Error |
| Reported by | PostSharp.Patterns.Model |
| Message | The type of field <Field> is not compatible with the [Recordable] aspect: type <FieldType> does not implement the IRecordable interface and does not have the [Recordable] aspect. |
Cause
Note
Undo/redo, and the RecordableAttribute aspect, are deprecated since PostSharp 2026.0.
The RecordableAttribute aspect records the changes of an object and of its children, the fields and properties marked with ChildAttribute, so that an undo reverts a change of a child together with the changes of its parent. A child can take part in the recording only when it is recordable itself.
PostSharp reports DOM022 on a child field of a reference type that implements neither IRecordable nor IDynamicallyAdvisable, when no RecordableAttribute aspect is applied to this type once PostSharp has discovered all the aspects of the project. Fields of an interface type and of type object are not checked, because the object that they hold at run time can be recordable. When the type of the child field is a standard collection, PostSharp reports COM008 instead.
In the following example, the address child field of the recordable Customer class has the type Address, which is not recordable.
// The Recordable aspect is deprecated.
#pragma warning disable CS0618
using System;
using PostSharp.Patterns.Model;
using PostSharp.Patterns.Recording;
namespace Errors.DOM022_Error;
public class Address
{
public string? City { get; set; }
}
[Recordable]
public class Customer
{
// The Address class is not recordable, so its changes cannot be undone with the customer.
[Child]
private readonly Address address = new Address();
public Address Address => this.address;
}
public static class Program
{
public static void Main()
{
var customer = new Customer();
customer.Address.City = "Prague";
customer.Address.City = "Brno";
RecordingServices.DefaultRecorder.Undo();
Console.WriteLine( $"City after undo: {customer.Address.City}" );
}
}
error DOM022: DOM022_Error.cs(20,30): The type of field Errors.DOM022_Error.Customer.address is not compatible with the [Recordable] aspect: type Errors.DOM022_Error.Address does not implement the IRecordable interface and does not have the [Recordable] aspect.
Resolution
- Add the RecordableAttribute aspect to the type of the child field.
- When the type cannot have the aspect, because it belongs to another library, exclude the field from the recording with NotRecordedAttribute, or remove ChildAttribute and make the field a reference with ReferenceAttribute.
In the following example, Address is recordable, so the undo reverts the change of its City property.
// The Recordable aspect is deprecated.
#pragma warning disable CS0618
using System;
using PostSharp.Patterns.Model;
using PostSharp.Patterns.Recording;
namespace Errors.DOM022_Fixed;
// The child class is recordable too.
[Recordable]
public class Address
{
public string? City { get; set; }
}
[Recordable]
public class Customer
{
[Child]
private readonly Address address = new Address();
public Address Address => this.address;
}
public static class Program
{
public static void Main()
{
var customer = new Customer();
customer.Address.City = "Prague";
customer.Address.City = "Brno";
RecordingServices.DefaultRecorder.Undo();
Console.WriteLine( $"City after undo: {customer.Address.City}" );
}
}
City after undo: Prague
See Also
Reference
RecordableAttribute
IRecordable
ChildAttribute
NotRecordedAttribute
Other Resources