| Severity | Warning |
| Reported by | Metalama.Framework |
| Message | The [ImmutableType] attribute on '<Type>' has no effect, because '<Type>' derives from or implements '<ContractType>', which already requires it. Remove the attribute. |
Cause
The [ImmutableType] attribute states that a type must be written in an immutable style. The requirement is inherited: it applies to every type that derives from, or implements, a type that requires it. For instance, IAspect and Fabric require immutability, so all aspects and fabrics are checked without any attribute of their own.
Metalama reports LAMA0886 when a type carries [ImmutableType] although it is already bound by the contract through a base type or an interface. Checking the type gives the same result with or without the attribute, so the attribute only suggests that removing it would relax something, when nothing would change. In the message, <Type> is the type that carries the attribute, and <ContractType> is the base type or interface that already requires immutability. This type isn't always marked with [ImmutableType] itself: some types, such as the validator base classes, are known to Metalama to require immutability.
This diagnostic is reported by a Roslyn analyzer, and snapshot tests of aspects don't run analyzers, so this article has no example.
Resolution
Remove the [ImmutableType] attribute from the type named in the message. The type remains subject to the immutability rules through <ContractType>.