Open sandboxFocusImprove this doc

LAMA0295: The declaration of a declarative advice can't be resolved

Severity Error
Reported by Metalama.Framework
Message Could not resolve the declaration with id '<DeclarationId>' while preparing the declarative advice of an aspect. That advice is ignored. This can happen when the declaration is absent from the compilation that the aspect runs against, or when several references of the compilation contain a type that is part of the signature of the declaration.

Cause

A declarative advice is an aspect member marked with an attribute derived from DeclarativeAdviceAttribute, typically [Introduce]. When Metalama loads an aspect class, it records the identifier of each of these members. Before it applies the aspect, it resolves these identifiers back to declarations in the compilation that contains the aspect class.

Metalama reports LAMA0295 when an identifier doesn't resolve. The placeholder of the message is the documentation identifier of the member, for example P:MyAspects.LogAttribute.Logger, which includes the name of the aspect type. Metalama skips this advice, but the other advice and aspects still run, and the error is reported once per identifier.

This situation isn't expected in a normal build. It can happen when:

  • the declaration is absent from the compilation that the aspect runs against, for instance at design time, when the IDE reuses the configuration of a previous compilation;
  • several referenced assemblies define a type with the same name, and this type is part of the signature of the declaration, so the type can't be resolved unambiguously.

Because this diagnostic depends on the state of the IDE or on the references of the project, it can't be shown in an example.

Resolution

  • If the error appears only in the IDE, rebuild the project, and restart the IDE if the error persists.
  • Look for a type of the member's signature that's defined in several referenced assemblies, for instance a type copied into two packages or a polyfill. Remove the duplicate, or make one of the copies internal.
  • Clean the solution, for instance by deleting the obj and bin folders, and rebuild.
  • If the error persists in a command-line build, report the issue to the Metalama team with the message and the declaration of the aspect.

See also