Skip to content

Lambda Generated Main Fails To Compile With Ambiguous Call Error #1907

Open
@grochoge

Description

Describe the bug

Trying to upgrade a .NET Lambda from Core 3.1 to 8.0 AOT. It takes no input and produces no output (it's just being used as a scheduled task).

I added a [assembly: LambdaGlobalProperties( GenerateMain = true )] attribute and added a [LambdaFunction] attribute to my function handler method, but compiling now gives error CS0121.

Note that the generated Program.g.cs is immediately deleted so I'm not able to examine it.

Regression Issue

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

Expected Behavior

Lambda generated main compiles

Current Behavior

Error (active) CS0121 The call is ambiguous between the following methods or properties: 'LambdaBootstrapBuilder.Create<TInput>(Func<TInput, Task>, ILambdaSerializer)' and 'LambdaBootstrapBuilder.Create<TOutput>(Func<Stream, TOutput>, ILambdaSerializer)' PROJECT PROJECTPATH\obj\Release\net8.0\Amazon.Lambda.Annotations.SourceGenerator\Amazon.Lambda.Annotations.SourceGenerator.Generator\Program.g.cs 25

Reproduction Steps

using System.Linq;
using System.Threading.Tasks;

using Amazon.EC2;
using Amazon.EC2.Model;
using Amazon.Lambda.Annotations;
using Amazon.Lambda.Core;

// Assembly attribute to enable the Lambda function's JSON input to be converted into a .NET class.
[assembly: LambdaSerializer( typeof( Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer ) )]
[assembly: LambdaGlobalProperties( GenerateMain = true )]

namespace  NAMESPACE
{
    public class Function : IDisposable
    {
        /// <summary>
        /// AWS EC2 API client
        /// </summary>
        private IAmazonEC2 EC2 { get; }

        /// <summary>
        /// Default contructor
        /// </summary>
        public Function()
        {
            EC2 = new AmazonEC2Client(  );
        }

        /// <summary>
        /// Dispose this object
        /// </summary>
        public void Dispose()
        {
            EC2.Dispose();
            return;
        }

        [LambdaFunction]
        public async Task FunctionHandler()
        {
            try
            {
                Logger.LogInfo( $"Function handler invoked at {DateTime.UtcNow.ToString("o")}" );
                await Task.Delay( 50 );
                Logger.LogInfo( $"Function handler finished at {DateTime.UtcNow.ToString("o")}" );
            }
            catch(Exception lEx)
            {
                Logger.LogError( $"Caught exception {lEx.Message}, stack trace : {lEx.StackTrace}" );
            }
        }
}

Possible Solution

No response

Additional Information/Context

No response

AWS .NET SDK and/or Package version used

    <PackageReference Include="Amazon.Lambda.Annotations" Version="1.6.2" />
    <PackageReference Include="Amazon.Lambda.Core" Version="2.5.0" />
    <PackageReference Include="Amazon.Lambda.RuntimeSupport" Version="1.12.2" />
    <PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.4.4" />
    <PackageReference Include="AWSSDK.CloudFormation" Version="3.7.401.11" />
    <PackageReference Include="AWSSDK.EC2" Version="3.7.425" />
    <PackageReference Include="AWSSDK.S3" Version="3.7.410.6" />
    <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />

Targeted .NET Platform

.NET 8.,0

Operating System and version

Compiling on Windows 10

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    annotationsbugThis issue is a bug.investigatingThis issue is being investigated and/or work is in progress to resolve the issue.p2This is a standard priority issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions