Open sandboxFocusImprove this doc

LAMA0090: Compile-time code requires a more recent C# language version

Severity Warning
Reported by Metalama.Framework
Message The compile-time code of '<ReferencedAssembly>' was compiled with the C# language version <RequiredVersion>, but the current process runs a version of Roslyn that supports at most the C# language version <SupportedVersion>. That code is read as C# <SupportedVersion> instead, and its compile-time build reports an error for each language feature above C# <SupportedVersion> that it uses. Use a more recent version of the .NET SDK or of the IDE, or compile '<ReferencedAssembly>' with the MetalamaTemplateLanguageVersion property set to <SupportedVersion> or lower.

Cause

When a project contains compile-time code, such as aspects, fabrics, or templates, Metalama embeds this code in the compiled assembly, together with the C# language version used to compile it. When another project references this assembly, Metalama compiles the embedded code again with the Roslyn compiler of the current process, at the same language version.

Metalama reports LAMA0090 when the referenced assembly requires a language version that is more recent than the highest version accepted by the Roslyn compiler that builds the current project. This typically happens when a library is built with a recent .NET SDK and consumed from a project built with an older SDK or an older version of the IDE.

In the message, <ReferencedAssembly> is the referenced assembly, <RequiredVersion> is the language version of its compile-time code, and <SupportedVersion> is the highest language version that the current compiler accepts.

Metalama can't use the more recent version, so it reads the compile-time code as the highest supported version. This is only a warning: if the compile-time code doesn't use any language feature above this version, the build succeeds. Otherwise, the compile-time build reports an error for each such feature. The required version is an upper bound derived from the project settings, not from the features that the code actually uses.

This diagnostic depends on the compiler installed on the machine and on the assemblies that you reference, so it can't be shown in an example.

Resolution

Use one of the following options:

  • Build the project with a more recent version of the .NET SDK, or of the IDE, that supports the language version required by the message.
  • If you maintain the referenced library, compile it with the MetalamaTemplateLanguageVersion property set to the supported version, or lower, so that its compile-time code stays readable by older compilers, and don't use newer language features in aspects, fabrics, and templates. See MSBuild properties and environment variables for details about this property.

See also