| Severity | Error |
| Reported by | Metalama.Framework |
| Message | Syntax error in generated code for file '<FilePath>': <OriginalMessage>. Location: Line <Line>, Column <Column>. Problematic code: '<ProblematicCode>'. |
Cause
Metalama transforms your code as syntax trees, not as text. A syntax tree can be valid while its text isn't, for instance when two tokens are written without the whitespace that separates them. Such a problem stays hidden during the build, but appears when the transformed code is written to disk, debugged, or parsed again.
When you set the MetalamaVerifyOutputCode MSBuild property to True, Metalama verifies the transformed code at the end of the build: it converts each transformed syntax tree to text and parses this text again with the C# parser. This verification is disabled by default.
Metalama reports LAMA0074 for each syntax error that the C# parser finds during this verification. In the message:
<FilePath>is the path of the source file whose transformed code is wrong.<OriginalMessage>is the message of the C# syntax error.<Line>and<Column>are the line and column of the error in the transformed code, not in your source file.<ProblematicCode>is the code around the error, truncated to 100 characters.
When the C# parser throws an exception instead of reporting errors, Metalama reports LAMA0073.
When the verification fails, the build fails too. If MetalamaDebugTransformedCode or MetalamaEmitCompilerTransformedFiles is enabled, Metalama still passes the transformed code to the compiler, so that the failing files are written to disk for inspection.
This diagnostic is caused by a defect in the code generation and only occurs with an opt-in MSBuild property, so it can't be shown in an example.
Resolution
- Set
MetalamaEmitCompilerTransformedFilestoTrueand rebuild, then open the transformed file named in the message at the line and column given in the message. See Debugging aspect-oriented code to find the transformed files. - If the faulty code comes from Metalama itself, check whether the problem is already fixed by updating the Metalama packages to the latest version of your release line. Otherwise, report the problem as described in How to file an issue, with the message and, if you can, a minimal project that reproduces it.
- If the faulty code comes from one of your aspects, for instance from code built as text, correct the template so that it produces valid C#.
- As a temporary workaround, remove the
MetalamaVerifyOutputCodeproperty. The verification is optional, but the problem it found may still cause other errors.