postsharp / Metalama

Metalama is a Roslyn-based meta-programming framework. Use this repo to report bugs or ask questions.
176 stars 5 forks source link

Error code LAMA0041 when switching to primary constructors (.NET 8 / C# 12) #244

Closed MEmanuelsson closed 10 months ago

MEmanuelsson commented 10 months ago

We have an aspect that injects a couple of dependencies into the class where the aspect is applied to a function. This works just fine in "regular" class in .NET 7 but now after upgrading to .NET 8 and adopting the new primary constructors that comes with C# 12 we get the following build error:

LAMA0041 'Exception of type 'System.InvalidCastException' thrown while executing BuildAspect for aspect [CacheAttribute] applied to 'ContentService.GetSiteContent(string, Guid, bool)': Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.Syntax.ClassDeclarationSyntax' to type 'Microsoft.CodeAnalysis.CSharp.Syntax.ConstructorDeclarationSyntax'. Exception details are in 'C:\Users\mtrmarema\AppData\Local\Temp\Metalama\CrashReports\2023.4.6\exception-6004c821-68b3-4510-a056-d45dcaa16584.txt'. To attach a debugger to the compiler, use the '-p:MetalamaDebugCompiler=True' command-line option. MotoritOnline.GraphQL.API C:\GIT\Motorit\MotoritOnline\Backend\Gateways\MotoritOnline.GraphQL.API\Services\ContentService.cs

I guess that Metalama at the moment doesn't support primary constructors?

PostSharpBot commented 10 months ago

Hello @MEmanuelsson, 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-34177.

MEmanuelsson commented 10 months ago

Reading this release post it feels like this could be expected: https://blog.postsharp.net/metalama-2023-4-ga.html. Looking forward to version 2024.0 :-)

addabis commented 10 months ago

Yes, indeed. Please note that this (injecting dependencies) is not yet implemented in the latest preview of 2024.0 and will produce a (user-friendly) error.

prochan2 commented 10 months ago

This bug has been fixed in Metalama 2024.0.3-preview.