Open sandboxFocusImprove this doc

LAMA1011: The call is already intercepted by a C# interceptor

Severity Error
Reported by Metalama.Extensions.Interceptors
Message The <Site> cannot be intercepted by the <Source> because the C# interceptor '<Interceptor>' already intercepts it.

Cause

C# itself supports interceptors: a method decorated with the InterceptsLocation attribute replaces a call at a given location. Source generators typically produce such methods. A call can have only one interceptor, whether it comes from C# or from Metalama.

Metalama reports LAMA1011 when a registration of Metalama.Extensions.Interceptors returns an interceptor for a call that the compiler already routes to a C# interceptor. In that case, Metalama doesn't intercept the call. In the message, <Site> describes the call, <Source> describes the aspect or fabric whose registration applies, and <Interceptor> is the C# interceptor method.

This diagnostic depends on a C# interceptor that a source generator or a hand-written file declares, and on the MSBuild property InterceptorsNamespaces that enables it, so it can't be shown in an example.

Resolution

Make sure that only one interceptor applies to the call:

  • Narrow the scope or the selection of the Metalama registration, so that it doesn't match the intercepted call. Alternatively, return Skip for this call in a ForEachSite delegate.
  • Exclude the code that contains the call from interception with the ExcludeInterceptors attribute.
  • Remove the C# interceptor, for instance by disabling the source generator that produces it for this call.

See also