Skip to content

AWS Lambda Test Tool 0.16.3 incompatible with .NET 8.0 Microsoft.Extensions packages - MissingMethodException #2263

@Jcobb27

Description

@Jcobb27

Describe the bug

The AWS .NET 8.0 Mock Lambda Test Tool version 0.16.3 fails to run .NET 8.0 Lambda functions locally that use Host.CreateDefaultBuilder() and Microsoft.Extensions.Hosting 8.0.0. The tool throws MissingMethodException errors for methods that exist in the .NET 8.0 runtime but are missing from the Test Tool's bundled runtime.

The Lambda function was working locally with the Test Tool after upgrading to .NET 8.0 awhile back. The issue appeared recently, suggesting the Test Tool auto-updated to 0.16.3 which introduced this incompatibility.

Regression Issue

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

Expected Behavior

The AWS .NET 8.0 Mock Lambda Test Tool should successfully run .NET 8.0 Lambda functions that use standard Microsoft.Extensions.Hosting 8.0.0 APIs including:

IHostBuilder.ConfigureServices()
HttpClientFactoryServiceCollectionExtensions.AddHttpClient()
ConsoleLoggerExtensions.AddConsole()

The Lambda should initialize and be testable locally just as it runs in the actual AWS Lambda environment.

Current Behavior

The Test Tool throws MissingMethodException errors during Lambda initialization:

System.MissingMethodException: Method not found: 'Microsoft.Extensions.Hosting.IHostBuilder Microsoft.Extensions.Hosting.IHostBuilder.ConfigureServices(System.Action`1<Microsoft.Extensions.DependencyInjection.IServiceCollection>)'.
at ...Function.constructor()

Additional missing methods:
Method not found: 'Microsoft.Extensions.DependencyInjection.IServiceCollection Microsoft.Extensions.DependencyInjection.HttpClientFactoryServiceCollectionExtensions.AddHttpClient(Microsoft.Extensions.DependencyInjection.IServiceCollection, System.String)'

Method not found: 'Microsoft.Extensions.Logging.ILoggingBuilder Microsoft.Extensions.Logging.ConsoleLoggerExtensions.AddConsole(Microsoft.Extensions.Logging.ILoggingBuilder)'

Reproduction Steps

  1. Create a .NET 8.0 Lambda function with the following packages:

Microsoft.Extensions.Hosting 8.0.0
Microsoft.Extensions.Http 8.0.0

  1. Use standard Host.CreateDefaultBuilder() pattern in the constructor:
public Function()
{
    var builder = Host.CreateDefaultBuilder();
    builder.ConfigureServices((context, services) =>
    {
        services.AddHttpClient("MyClient");
        services.AddTransient<App>();
    })
    .ConfigureLogging((logging) =>
    {
        logging.AddConsole();
        logging.AddLambdaLogger();
    });

    AppHost = builder.Build();
    ServiceProvider = AppHost.Services;
}
  1. Run the Lambda locally using AWS Lambda Test Tool 0.16.3 in Visual Studio
  2. Observe MissingMethodException errors

Possible Solution

The Test Tool 0.16.3 appears to bundle an older version of Microsoft.Extensions runtime that doesn't include .NET 8.0 APIs. The tool should either:

1.Include the full .NET 8.0 Microsoft.Extensions runtime, or
2.Use the host machine's installed .NET 8.0 runtime instead of bundling its own

Additional Information/Context

Attempting to manually downgrade to Test Tool 0.15.0 using dotnet tool install -g Amazon.Lambda.TestTool-8.0 --version 0.15.0 gets overridden back to 0.16.3 when running from Visual Studio

Visual Studio shows "AWS .NET 8.0 Mock Lambda Test Tool (0.16.3)" when launching

The issue affects standard Lambda patterns documented in AWS samples

AWS .NET SDK and/or Package version used

Amazon.Lambda.Core 2.2.0
Amazon.Lambda.Serialization.SystemTextJson 2.4.3
Amazon.Lambda.SQSEvents 2.2.0
Microsoft.Extensions.Hosting 8.0.0
Microsoft.Extensions.Http 8.0.0
AWS Lambda Test Tool: 0.16.3

Targeted .NET Platform

.NET 8.0

Operating System and version

Windows 11

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions