IntroduceDependencyAttribute isn't working on record types
LanceXact opened this issue · 3 comments
The IntroduceDependencyAttribute used within the SimpleLogAttribute to inject an ILogger _logger isn't working on record types at compile-time. I'm getting this error:
Severity Code Description Project File Line Suppression State
Error LAMA0041 'OverrideMethodAspect.BuildAspect' threw 'InvalidCastException' when applied to 'SomeRecord.GetValue()': Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.Syntax.RecordDeclarationSyntax' to type 'Microsoft.CodeAnalysis.CSharp.Syntax.ConstructorDeclarationSyntax'. Exception details are in 'C:\Users\xxxxx\AppData\Local\Temp\Metalama\CrashReports\2023.2.5\exception-f187d93b-fe84-4ec8-8ded-e0785ba642aa.txt'. To attach a debugger to the compiler, use the '-p:MetalamaDebugCompiler=True' command-line option. Entities C:\Source\xxxx\SomeRecord.cs 11 Active
Here's the offending record type (I created a tiny reproducible version):
public record SomeRecord(string Value)
{
public string GetValue()
{
return Value;
}
}
Hello @LanceXact, thank you for submitting this issue. We will try to get back to you as soon as possible.
Note to the PostSharp team, this ticket is being tracked in our dashboard under ID TP-33922.
We have reproduced the issue on our side.
The underlying API that [IntroduceDependency]
uses currently does not support records, but you should get a more user-friendly error rather than this exception.
We will be working on improving this. Thanks a lot for the report.
This bug has been fixed in Metalama 2024.0.3-preview.