Skip to content

Decorating async Task function with [LambdaFunction] generates compile error #1200

@hounddog22030

Description

@hounddog22030

Describe the bug

The generated code is awaiting the Task and attempting to return the Task, but because the original method is async, the original method is really a void, so it cannot be returned.

Expected Behavior

No compile errors.

Current Behavior

Receive Compile Error:

Severity	Code	Description	Project	File	Line
Error	CS1997	Since 'Functions_SqsMessageHandler_Generated.SqsMessageHandler(SQSEvent.SQSMessage, ILambdaContext)' is an async method that returns 'Task', a return keyword must not be followed by an object expression. Did you intend to return 'Task<T>'?	ServerlessWithSqs	C:\Users\17034\source\repos\ServerlessWithSqs\ServerlessWithSqs\Amazon.Lambda.Annotations.SourceGenerator\Amazon.Lambda.Annotations.SourceGenerator.Generator\Functions_SqsMessageHandler_Generated.g.cs	35

Reproduction Steps

Steps to reproduce:

  1. Create a new serverless project
  2. Choose the Annotations blueprint
  3. In Function.cs add the below code:
    [LambdaFunction]
    public async Task SqsMessageHandler(SQSEvent.SQSMessage sqsMessage, ILambdaContext context)
    {
        await Task.Delay(1);
    }

  1. Build the project

Possible Solution

remove the return?
return without the await?

Additional Information/Context

No response

AWS .NET SDK and/or Package version used

<PackageReference Include="Amazon.Lambda.Annotations" Version="0.5.0-preview" />

Targeted .NET Platform

.NET 6

Operating System and version

Windows 11, AmazonLinux

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions