| Severity | Error |
| Reported by | Metalama.Framework |
| Message | The compile-time code of the project contains C# errors, so it cannot be compiled. Fix the C# errors reported in the compile-time code. |
Cause
Before Metalama can execute your aspects, fabrics, and other compile-time types, it compiles them into a separate compile-time assembly. To do this, Metalama first checks every compile-time type of the project for C# errors.
When a compile-time type contains C# errors, Metalama reports these errors and can't build the compile-time assembly. It then also reports LAMA0068, so that the failure is never silent. LAMA0068 itself has no location: the C# errors reported next to it point to the faulty code.
In the following example, the aspect calls a method that doesn't exist on builder, so the aspect doesn't compile. Metalama reports LAMA0068 together with the C# error CS1061.
1using Metalama.Framework.Aspects;
2using Metalama.Framework.Code;
3using System;
4
5namespace Doc.LAMA0068.Error;
6
7public class LogAttribute : MethodAspect
8{
9 public override void BuildAspect( IAspectBuilder<IMethod> builder )
10 {
11 // Error: the Overide method does not exist, so the aspect contains a C# error.
Error CS1061: 'IAspectBuilder<IMethod>' does not contain a definition for 'Overide' and no accessible extension method 'Overide' accepting a first argument of type 'IAspectBuilder<IMethod>' could be found (are you missing a using directive or an assembly reference?)
12 builder.Overide( nameof(this.OverrideMethod) );
13 }
14
15 [Template]
16 private dynamic? OverrideMethod()
17 {
18 Console.WriteLine( $"Executing {meta.Target.Method}." );
19
20 return meta.Proceed();
21 }
22}
23
1namespace Doc.LAMA0068.Error;
2
3internal class OrderService
4{
5 [Log]
6 public void PlaceOrder( string product, int quantity ) { }
7}
8
Resolution
- Look at the other errors of the build, typically
CSerrors, and find the ones located in compile-time code: aspects, fabrics, templates, or types marked with [CompileTime] or [RunTimeOrCompileTime]. - Fix these errors. Remember that compile-time code can only use the .NET Standard 2.0 API, the Metalama API, and the packages explicitly made available to compile-time code.
- Rebuild the project. LAMA0068 disappears when the compile-time code compiles.
In the following example, the aspect calls the existing Override method.
1using Metalama.Framework.Aspects;
2using Metalama.Framework.Code;
3using System;
4
5namespace Doc.LAMA0068.Fixed;
6
7public class LogAttribute : MethodAspect
8{
9 public override void BuildAspect( IAspectBuilder<IMethod> builder )
10 {
11 // Fixed: call the Override method.
12 builder.Override( nameof(this.OverrideMethod) );
13 }
14
15 [Template]
16 private dynamic? OverrideMethod()
17 {
18 Console.WriteLine( $"Executing {meta.Target.Method}." );
19
20 return meta.Proceed();
21 }
22}
23
1namespace Doc.LAMA0068.Fixed;
2
3internal class OrderService
4{
5 [Log]
6 public void PlaceOrder( string product, int quantity ) { }
7}
8
1using System;
2
3namespace Doc.LAMA0068.Fixed;
4
5internal class OrderService
6{
7 [Log]
8 public void PlaceOrder(string product, int quantity)
9 {
10 Console.WriteLine("Executing OrderService.PlaceOrder(string, int).");
11 }
12}
13