Open sandboxFocusImprove this doc

LAMA0052: The C# language version isn't supported

Severity Error
Reported by Metalama.Framework
Message The C# language version '<SelectedVersion>' is not supported. Change the <<PropertyName>> property of your project file to one of the following supported values: <SupportedVersions>. Do not use 'latest' or 'latestMajor' because these values are interpreted inconsistently when you use a .NET SDK or IDE that is more recent than Metalama.

Cause

Each version of Metalama supports a fixed set of C# language versions, starting with C# 10. The message lists them. Metalama reports LAMA0052 in two situations:

  • When it compiles a project whose C# language version, given by the LangVersion MSBuild property, isn't supported. This happens with a version that's too old, such as C# 8.0 or 9.0, or with latest or latestMajor when the .NET SDK supports a more recent C# version than Metalama. Metalama then stops processing the project, so no aspect is applied. This check runs only during the build, not in the IDE.
  • When the MetalamaTemplateLanguageVersion MSBuild property, which limits the C# syntax allowed in templates, has a value that isn't a supported C# version.

In the message, <SelectedVersion> is the invalid version, <PropertyName> is the name of the MSBuild property to change, and <SupportedVersions> is the list of supported versions. The diagnostic isn't attached to any location in the source code.

In the following example, the project is compiled with C# 8.0.

1using Metalama.Framework.Aspects;
2using System;
3
4namespace Doc.LAMA0052.Error
5{
6    public class LogAttribute : OverrideMethodAspect
7    {
8        public override dynamic? OverrideMethod()
9        {
10            Console.WriteLine( $"Executing {meta.Target.Method}." );
11
12            return meta.Proceed();
13        }
14    }
15}
16
1namespace Doc.LAMA0052.Error
2{
3    public class Calculator
4    {
5        [Log]
6        public int Add( int a, int b ) => a + b;
7    }
8}
9

Resolution

Set the MSBuild property given in the message to one of the supported versions, using an explicit version number, as in the following example. Avoid latest and latestMajor: their meaning depends on the compiler that builds the project, so they can select a C# version that's more recent than the versions your release of Metalama supports.

If you need a C# version that's more recent than the supported ones, update Metalama to a release that supports it.

1using Metalama.Framework.Aspects;
2using System;
3
4namespace Doc.LAMA0052.Fixed
5{
6    public class LogAttribute : OverrideMethodAspect
7    {
8        public override dynamic? OverrideMethod()
9        {
10            Console.WriteLine( $"Executing {meta.Target.Method}." );
11
12            return meta.Proceed();
13        }
14    }
15}
16
Source Code
1namespace Doc.LAMA0052.Fixed
2{
3    public class Calculator
4    {


5        [Log]
6        public int Add( int a, int b ) => a + b;
7    }
8}
9
Transformed Code
1using System;
2
3namespace Doc.LAMA0052.Fixed
4{
5    public class Calculator
6    {
7        [Log]
8        public int Add(int a, int b)
9        {
10            Console.WriteLine("Executing Calculator.Add(int, int).");
11            return a + b;
12        }
13    }
14}
15

See also