Open sandboxFocusImprove this doc

LAMA0051: Metalama doesn't support the preview C# language version

Severity Error
Reported by Metalama.Framework
Message Metalama does not support the 'preview' language version. Change the LangVersion property of your project file to one of the following supported values: <SupportedVersions>. If you want to use preview features at your own risk, set the MSBuild property 'MetalamaAllowPreviewLanguageFeatures' to 'true'. This may work if you do not use preview features in templates.

Cause

Each version of Metalama supports a fixed set of C# language versions. The preview features of the next C# version can change at any time, so Metalama can't guarantee that it handles them correctly, especially in templates.

When Metalama compiles a project, it checks the C# language version of the project, given by the LangVersion MSBuild property. Metalama reports LAMA0051 when this version is preview and the MetalamaAllowPreviewLanguageFeatures property isn't set to true. It then stops processing the project, so no aspect is applied. In the message, <SupportedVersions> is the list of supported C# versions.

The diagnostic isn't attached to any location in the source code. Metalama reports it only during the build, not in the IDE.

This diagnostic depends on the LangVersion and MetalamaAllowPreviewLanguageFeatures MSBuild properties, and snapshot tests that request the preview language version always allow the preview language features, so it can't be shown in an example.

Resolution

Do one of the following:

  • Set the LangVersion property of the project to one of the supported versions listed in the message. Prefer an explicit version number to latest or latestMajor, whose meaning depends on the compiler (see LAMA0052).
  • If you need preview features, set the MetalamaAllowPreviewLanguageFeatures MSBuild property to true. Metalama then processes the project, but at your own risk. It's more likely to work if your templates don't use preview features.

See also