| Severity | Warning |
| Reported by | Metalama.Framework |
| Message | The compile-time declaration '<Declaration>' is in a file that does not have a using directive for the '<Namespace>' namespace or one of its main child namespaces. This may cause an inconsistent design-time experience. Add a using directive such as 'using <Namespace>.Aspects;' to the file. |
Cause
To keep the IDE responsive, Metalama decides which files contain compile-time code with a fast check that only looks at the using directives of each file. A file passes this check only if it has a using directive for Metalama.Framework or one of its main child namespaces, such as Metalama.Framework.Aspects, Metalama.Framework.Code, or Metalama.Framework.Fabrics, or if it has a global using directive.
Metalama reports LAMA0119 when a file fails this fast check but still declares compile-time or run-time-or-compile-time code, for instance a class marked with [CompileTime], an aspect, or a fabric. This typically happens when you reference Metalama types by their fully qualified names or through a using alias. The build itself still works, but at design time, Metalama may not notice when you edit this file, so the IDE can show outdated or inconsistent results.
Metalama reports the warning on each compile-time declaration of the file, so you may see it on both a type and its members.
In the following example, the LogFormatter helper class is marked with the fully qualified [Metalama.Framework.Aspects.CompileTime] attribute, and its file has no using directive.
1using Metalama.Framework.Aspects;
2using System;
3
4namespace Doc.LAMA0119.Error;
5
6public class LogAttribute : OverrideMethodAspect
7{
8 public override dynamic? OverrideMethod()
9 {
10 Console.WriteLine( LogFormatter.GetEntryMessage( meta.Target.Method.Name ) );
11
12 return meta.Proceed();
13 }
14}
15
1namespace Doc.LAMA0119.Error;
2
3internal class Calculator
4{
5 [Log]
6 public int Add( int a, int b ) => a + b;
7}
8
1using System;
2
3namespace Doc.LAMA0119.Error;
4
5internal class Calculator
6{
7 [Log]
8 public int Add(int a, int b)
9 {
10 Console.WriteLine("Entering Add.");
11 return a + b;
12 }
13}
14
1namespace Doc.LAMA0119.Error;
2
3// Warning: the file contains compile-time code but no using directive for a Metalama.Framework namespace.
4[Metalama.Framework.Aspects.CompileTime]
Warning LAMA0119: The compile-time declaration 'LogFormatter' is in a file that does not have a using directive for the 'Metalama.Framework' namespace or one of its main child namespaces. This may cause an inconsistent design-time experience. Add a using directive such as 'using Metalama.Framework.Aspects;' to the file.
5internal static class LogFormatter
6{
Warning LAMA0119: The compile-time declaration 'LogFormatter.GetEntryMessage(string)' is in a file that does not have a using directive for the 'Metalama.Framework' namespace or one of its main child namespaces. This may cause an inconsistent design-time experience. Add a using directive such as 'using Metalama.Framework.Aspects;' to the file.
7 public static string GetEntryMessage( string methodName ) => $"Entering {methodName}.";
8}
9
Resolution
Add a using directive for a Metalama namespace to the file, typically using Metalama.Framework.Aspects;, and use the short names of the Metalama types. In the following example, the file imports Metalama.Framework.Aspects and the class uses the short [CompileTime] attribute.
1using Metalama.Framework.Aspects;
2using System;
3
4namespace Doc.LAMA0119.Fixed;
5
6public class LogAttribute : OverrideMethodAspect
7{
8 public override dynamic? OverrideMethod()
9 {
10 Console.WriteLine( LogFormatter.GetEntryMessage( meta.Target.Method.Name ) );
11
12 return meta.Proceed();
13 }
14}
15
1using Metalama.Framework.Aspects;
2
3namespace Doc.LAMA0119.Fixed;
4
5// Fixed: the file imports the Metalama.Framework.Aspects namespace.
6[CompileTime]
7internal static class LogFormatter
8{
9 public static string GetEntryMessage( string methodName ) => $"Entering {methodName}.";
10}
11
1namespace Doc.LAMA0119.Fixed;
2
3internal class Calculator
4{
5 [Log]
6 public int Add( int a, int b ) => a + b;
7}
8
1using System;
2
3namespace Doc.LAMA0119.Fixed;
4
5internal class Calculator
6{
7 [Log]
8 public int Add(int a, int b)
9 {
10 Console.WriteLine("Entering Add.");
11 return a + b;
12 }
13}
14