| Severity | Error |
| Reported by | Metalama.Framework |
| Message | The aspect '<AspectType>' cannot introduce a member of kind '<IntroducedDeclarationKind>' because it has been applied to a declaration of kind '<TargetDeclarationKind>', which is neither a type nor a type member. |
Cause
When an aspect class contains members marked with the [Introduce] custom attribute, Metalama introduces these members into the type that the aspect targets. If the aspect is applied to a type, members are introduced into this type. If it's applied to a member, such as a method or a property, members are introduced into the declaring type of this member.
Metalama reports LAMA0700 when it executes such an aspect on a declaration that has no declaring type: a parameter, a generic parameter, a namespace, or the project. In the message, <AspectType> is the aspect, <IntroducedDeclarationKind> is the kind of the member to introduce, and <TargetDeclarationKind> is the kind of the target declaration.
In practice, you're unlikely to see this diagnostic. The [Introduce] attribute adds an eligibility condition to the aspect, requiring the target to be a type or a type member. When you apply the aspect to another kind of declaration, Metalama reports the eligibility error LAMA0037 instead, before it executes the aspect.
Metalama combines the eligibility conditions of all [Introduce] members of the aspect and applies them to every target, so the eligibility check can't be bypassed and this diagnostic can't be shown in an example.
Resolution
Do one of the following:
- Apply the aspect to a type or to a member of a type instead of a parameter, a namespace, or the project.
- If the aspect must target a parameter or another declaration, remove the [Introduce] members and introduce the members programmatically from
BuildAspect. Use the With method of the aspect builder to select the declaring type, then call methods such as IntroduceMethod. - To add an aspect to all types of a namespace or project, use a fabric that selects the types and adds the aspect to them.