aws/aws-lambda-dotnet

Error with code generated with Amazon.Lambda.Annotations (event property must have both add and remove accessors)

romulomrossi-caylent opened this issue · 6 comments

Describe the bug

I'm trying to implement a Lambda function that a Step Function will trigger. I'm using the LambdaFunction decorator, as well as the LambdaStartup.

Image

But I'm getting the following errors from the dotnet build:

/FacStats/Amazon.Lambda.Annotations.SourceGenerator/Amazon.Lambda.Annotations.SourceGenerator.Generator/FacStatsProcessor_ProcessFacilityStats_Generated.g.cs(48,94): error CS0065: 'FacStatsProcessor_ProcessFacilityStats_Generated.': event property must have both add and remove accessors

/FacStats/Amazon.Lambda.Annotations.SourceGenerator/Amazon.Lambda.Annotations.SourceGenerator.Generator/FacStatsProcessor_ProcessFacilityStats_Generated.g.cs(48,50): error CS1994: The 'async' modifier can only be used in methods that have a body.

/FacStats/Amazon.Lambda.Annotations.SourceGenerator/Amazon.Lambda.Annotations.SourceGenerator.Generator/FacStatsProcessor_ProcessFacilityStats_Generated.g.cs(56,63): error CS0102: The type 'FacStatsProcessor_ProcessFacilityStats_Generated' already contains a definition for ''

Thank you in advance for any help.

Regression Issue

  • Select this option if this issue appears to be a regression.

Expected Behavior

Generated code to be successfully built.

Current Behavior

Build fails with the errors in the description.

Reproduction Steps

Just try to implement a handler with only the LambdaHandler decorator. I tested it, and it works if I add the [HttpApi()] decorator, but I don't want it to receive any API requests.

Possible Solution

No response

Additional Information/Context

No response

AWS .NET SDK and/or Package version used

<PackageReference Include="Amazon.Lambda.RuntimeSupport" Version="1.12.0" />
<PackageReference Include="Amazon.Lambda.Core" Version="2.5.0" />
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.4.4" />
<PackageReference Include="Amazon.Lambda.Annotations" Version="1.6.1" />

Targeted .NET Platform

.NET 8

Operating System and version

MacOS Sequoia 15.0 (24A335)

Interesting I think the @ on the @event parameter of the ProcessFacilityStats is tripping up the source generator. We will need to look into what is going on. Can you rename the parameter to something without the @ like evnt?

Actually the problem is the source generator gets the name of the parameter as just event and uses that which causes problems since that is keyword. Here is what the generated code looks like. So the work around is naming it something that isn't a reserved word even with the @ prefix.

        public async System.Threading.Tasks.Task ProcessFacilityStats(FacStats.Facility event, Amazon.Lambda.Core.ILambdaContext __context__)
        {
            // Create a scope for every request,
            // this allows creating scoped dependencies without creating a scope manually.
            using var scope = serviceProvider.CreateScope();
            var functions = scope.ServiceProvider.GetRequiredService<Functions>();
            var serializer = scope.ServiceProvider.GetRequiredService<Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer>();

            await functions.ProcessFacilityStats(event, __context__);
        }

I changed the name, and it worked. It's a minor problem, and using the @ on reserved words is not a very popular practice, so I'll close the issue. Thank you very much!

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

@romulomrossi-caylent Glad you are able to move forward. I created an issue in our backlog for this bug. Like you said it is a uncommon scenario with an easy work around so we probably won't get to it for awhile.