Metalama Diagnostics Not Being Reported Correctly

3 weeks ago 11
ARTICLE AD BOX

I am implementing a method aspect and I need to check that the return value specified in the attribute matches the method's return type (or can be safely cast to it).

I defined by aspect like so:

[AttributeUsage(AttributeTargets.Method)] public class ExceptionReturnValueAttribute : MethodAspect { private static readonly DiagnosticDefinition<string> InvalidReturnType = new("MY1023", Severity.Error, "{0}" ); public override void BuildAspect(IAspectBuilder<IMethod> builder) { var isReturnTypeValid = IsReturnTypeValid(builder.Target.ReturnType.ToType()); if (!isReturnTypeValid.IsValid) { builder.Diagnostics.Report(InvalidReturnType.WithArguments(isReturnTypeValid.Message)); } } }

This is correctly detecting the mismatched types as the project won't build and I see the diagnostic in the error window. However, instead of seeing MY1023 in the code column and then my description, I see LAMA0301 and then in the Description column is says:

MY1023: <my message> MY1023 was not defined in the user profile and has been replaced by a generic diagnostic ID.

However, I don't understand why the ID is being replaced. The diagnostic is defined as a static readonly field, I am calling it with builder.Diagnostic.Report, and the message is correct, so I am not understanding why it is saying it is not defined in the user profile and replacing it with its own LAMA code.

Is there something else I am missing or require as this seemed to be all that was supposed to be needed according to their documentation. Any help/guidance would be greatly appreciated. TIA.

Read Entire Article