IntroduceDependency with record types

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\xxxx\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;
}
}
public record SomeRecord(string Value)
{
public string GetValue()
{
return Value;
}
}
4 Replies
Lance
LanceOP•14mo ago
Now that I think about it maybe auto-injecting a logger into a record type doesn't make much sense 🤔
Petr Onderka
Petr Onderka•14mo ago
Thanks for the report. This is a bug in Metalama. Can you create an issue on our GitHub (https://github.com/postsharp/Metalama/issues/new) for this?
Lance
LanceOP•14mo ago
GitHub
IntroduceDependencyAttribute isn't working on record types · Issue ...
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 Descrip...
Whit
Whit•14mo ago
Though I can see it making more sense if it still bugs in the next version of C# with implicit class constructors.
Want results from more Discord servers?
Add your server