aws / aws/aws-lambda-dotnet

Lambda Generated Main Fails To Compile With Ambiguous Call Error

Open
#1,907 2 comments 0 reactions 0 assignees View on GitHub
annotations bug investigating p2
Dominant language
C#
Stars
1.7k
Forks
503
Avg merge
1d 5h
Merged PRs (30d)
18

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(Func, ILambdaSerializer)' and 'LambdaBootstrapBuilder.Create(Func, ILambdaSerializer)' PROJECT PROJECTPATH\obj\Release\net8.0\Amazon.Lambda.Annotations.SourceGenerator\Amazon.Lambda.Annotations.SourceGenerator.Generator\Program.g.cs 25`

### Reproduction Steps

```c#
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
{
///
/// AWS EC2 API client
///
private IAmazonEC2 EC2 { get; }

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

///
/// Dispose this object
///
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

```








```

### Targeted .NET Platform

.NET 8.,0

### Operating System and version

Compiling on Windows 10

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.