| Severity | Warning |
| Reported by | Metalama.Framework (Roslyn analyzer) |
| Message | '<Type>' is marked [Durable] but its base type '<BaseType>' is not durable. Retention path: <RetentionPath>. |
Cause
Applying [Durable] (defined in the Metalama.Framework.Utilities namespace) to a type declares that its instances are safe to keep across compilations: no instance field or automatically implemented property may hold a compilation, a syntax tree, a symbol, or anything that reaches one. See LAMA0870 for the full rationale. An instance of a derived type also contains the fields of its base class, so a durable type can't derive from a base class that isn't durable.
Metalama reports LAMA0873 when a type that is subject to the contract has a base class that isn't durable. A type is subject to the contract when it is marked [Durable], or when it derives from or implements a type marked [Durable]. The analyzer ignores object and System.ValueType as base types. It reports the warning once on the derived type, and not on each inherited member, because the author of the derived type can't fix the members that the base class declares. In the message, <Type> is the derived type, <BaseType> is its base class, and <RetentionPath> is the chain of types that explains why the base class isn't durable, followed by the reason in parentheses.
The analyzer runs in the compiler and in the IDE, not in the Metalama aspect pipeline, so this diagnostic can't be shown in an example that runs a Metalama aspect test.
Resolution
- Make the base class durable. If you own the base class and it holds only durable members, mark it
[Durable]. The analyzer then verifies its members, and reports LAMA0870 for each member that isn't durable. - Change the base class. Remove the inheritance, or derive from a base class that is durable, and use composition for the behavior that you need.
- Remove
[Durable]from the derived type if its instances aren't held across compilations.