Open sandboxFocusImprove this doc

LAMA0405: Metalama can't set a property of the custom attribute

Severity Error
Reported by Metalama.Framework
Message Cannot instantiate a custom attribute: the property '<Property>' has no setter.

Cause

When an aspect, or another compile-time attribute, is applied with a custom attribute, Metalama instantiates the attribute class at compile time: it calls the constructor, then sets the properties and fields assigned with named arguments, as in [Log( Category = "Billing" )]. It finds the properties of the attribute class with reflection.

Metalama reports LAMA0405 when it finds the property named <Property> by reflection but can't find any setter for it, public or not. Metalama looks for the setter in the attribute class and, when the property overrides a base property that has a setter, in the base classes, as C# does.

The C# compiler already rejects a named argument for a property without a setter, so this diagnostic isn't expected in normal code, and no scenario is known to trigger it. It's a safety check, so the article has no example.

Resolution

  • Make sure that the property named in the custom attribute is a read-write property of the attribute class or of one of its base classes, and that the project compiles without C# errors.
  • If the error persists on code that the C# compiler accepts, report it to the Metalama team, with the declaration of the attribute class.

See also