| Severity | Error |
| Reported by | Metalama.Framework |
| Message | Cannot generate the initializer of '<Member>': <ExceptionMessage> |
Cause
When an aspect introduces a field, a property, or an event, it can give the member an initial value by setting the InitializerExpression property of the member builder to an IExpression. When Metalama generates the code of the introduced member, it converts this expression into C# syntax.
Metalama reports LAMA0064 when this conversion throws an exception. In the message, <Member> is the introduced member, and <ExceptionMessage> is the message of the exception.
Expressions created with the Metalama APIs normally convert without error, so this diagnostic usually indicates a problem in Metalama rather than in your aspect. For this reason, it can't be shown in an example.
Resolution
- Read the reason given at the end of the message. It often identifies the part of the expression that couldn't be generated.
- Simplify the initializer. For instance, instead of building an IExpression in
BuildAspect, pass an initializer template to the IntroduceField, IntroduceProperty, or IntroduceEvent advice, or parse the expression from text with ExpressionFactory.Parse. - If the problem persists, update the Metalama packages to the latest version of your release line, and report the problem as described in How to file an issue.