-
I've declared the BuildEligibility on three aspects indicating the following: //Type cannot be static
builder.MustSatisfy(t => !t.IsStatic, t => $"The type cannot be static");
//Type cannot be a record type
builder.MustSatisfy(t => t.TypeKind is not (TypeKind.RecordStruct or TypeKind.RecordClass),
x => $"Cannot inject into a record type");
//Type must be explicitly declared
builder.MustBeExplicitlyDeclared(); I've then got a fabric that's attempting to broadly apply aspects to those types with more than one method that don't implement a base type called "Workflow", but to only add the aspect if eligible: public sealed class Fabric : TransitiveProjectFabric
{
public override void AmendProject(IProjectAmender amender)
{
amender.SelectMany(p => p.Types)
.Where(t => t.Methods.Count > 0) //Should have at least one method to decorate or no point
.Where(t => t.BaseType?.Name != "Workflow") //Should not log within Dapr Workflow instances
.AddAspectIfEligible<InjectLoggerAttribute>();
}
} The aspect has an intended application order: [assembly: AspectOrder(AspectOrderDirection.RunTime, typeof(LogAttribute), typeof(InjectLoggerFactoryAttribute), typeof(InjectLoggerAttribute))] And the builder.Outbound.SelectMany(a => a.Constructors)
.AddAspectIfEligible<InjectLoggerFactoryAttribute>();
builder.Outbound.SelectMany(a => a.Methods)
.AddAspectIfEligible<LogAttribute>(); Nonetheless, I'm showing errors in VS that Metalama has paused analysis of the project because of errors in the compile-time code. When I dig into what these errors are, I'm seeing that it's because the fabric appears to be applying the aspect to types that match the fabric, but should be deemed ineligible per the eligibility methods on each aspect: I would instead expect that the following would happen:
Rather, it appears to be ignoring the eligibility check on the Am I doing something wrong here or should I re-file this as a bug report? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 7 replies
-
On the theory that perhaps I'm applying the eligibility incorrectly by specifying all the individual builder.MustSatisfyAll(
//Must be explicitly declared
_ => builder.MustBeExplicitlyDeclared(),
//Must not be static
_ => builder.MustSatisfy(t => !t.IsStatic, n => $"The method cannot be static"),
//Must not be a record type
_ => builder.DeclaringType().MustSatisfy(t => t.TypeKind is not (TypeKind.RecordStruct or TypeKind.RecordClass),
x => $"The declaring type must not be a record")); Nonetheless, I still see precisely the same thing happening in that it's attempting to apply the aspect to the static class and, of course, failing. |
Beta Was this translation helpful? Give feedback.
-
Can you provide the crash report mentioned in the error message? Thanks. |
Beta Was this translation helpful? Give feedback.
-
Though I don't see why the eligibility check for So, as far as I can tell, what should and does happen here is:
The exception indicates there is still some problem here (possibly a bug in Metalama), but I don't think it's related to eligibility. |
Beta Was this translation helpful? Give feedback.
-
The bug is fixed in 2024.2.25. |
Beta Was this translation helpful? Give feedback.
When I built your solution, I got the following error:
Once I fixed that, by changing the method to the following, things started working.