Open sandboxFocusImprove this doc

LAMA0876: An interface or abstract type used by a durable type is not marked [Durable]

Severity Warning
Reported by Metalama.Framework (Roslyn analyzer)
Message '<Type>' does not satisfy the [Durable] contract because '<MemberType>' is not marked [Durable]. Marking it requires every implementation to be durable, which this analyzer verifies. Retention path: <Path>.

Cause

A type bound by the durable contract, that is, a type marked [Durable] (from the Metalama.Framework.Utilities namespace) or one that derives from or implements such a type, must hold only durable values: every instance field and automatically implemented property must have a durable type. Durability is opt-in, so a type is durable only if it is marked [Durable] or is otherwise known to the analyzer, such as an intrinsic type or a system collection of durable types.

An interface or an abstract class is a special case. It has no implementation that the analyzer could check, so it can't tell whether the value stored in the member is durable. The remedy also differs from the one for a concrete class, which is why this situation has its own diagnostic.

The analyzer reports LAMA0876 on the member when its type, or a type argument or element type reached from it, is an interface or an abstract type without the [Durable] attribute. In the message, <Type> is the durable type that declares the member, <MemberType> is the type of the member, and <Path> is the chain of members and types that leads from the durable type to the type that isn't marked.

This diagnostic is reported by a Roslyn analyzer, which snapshot tests of aspects don't run, so it can't be shown in an example.

Resolution

Choose one of the following, depending on your design:

  • Mark the interface or abstract class named in the retention path with [Durable]. The obligation then applies to every implementation or derived type, and the analyzer verifies each one in turn. Use this when all implementations are meant to be held across compilations.
  • Mark the member itself with [Durable]. The analyzer then doesn't check the declared type and checks instead that every value assigned to the member is durable. The member must be read-only or private, or have a private setter, otherwise LAMA0877 is reported.
  • Change the member to a type that is durable.

See also