Aws-lambda-dotnet: Getting MissingMethodException when using standard libraries

Created on 13 May 2020  路  7Comments  路  Source: aws/aws-lambda-dotnet

I have a "factory" class tat sets up some dependency injection inside of my Aws Lambda:

var serviceProvider = new ServiceCollection()
                .AddHttpClient()
..... Other services

and when I run the test tool it throws back:

System.MissingMethodException: Method not found: 'Microsoft.Extensions.DependencyInjection.IServiceCollection Microsoft.Extensions.DependencyInjection.HttpClientFactoryServiceCollectionExtensions.AddHttpClient(Microsoft.Extensions.DependencyInjection.IServiceCollection)'.
   at Factories.ProcessorFactory.CreateProcessor()
   // Handle event method
   at Amazon.Lambda.TestTool.Runtime.LambdaExecutor.ProcessReturnAsync(ExecutionRequest request, Object lambdaReturnObject) in C:\codebuild\tmp\output\src142363207\src\Tools\LambdaTestTool\src\Amazon.Lambda.TestTool\Runtime\LambdaExecutor.cs:line 141
   at Amazon.Lambda.TestTool.Runtime.LambdaExecutor.ExecuteAsync(ExecutionRequest request) in C:\codebuild\tmp\output\src142363207\src\Tools\LambdaTestTool\src\Amazon.Lambda.TestTool\Runtime\LambdaExecutor.cs:line 62

Heres a dump of the aws-lambda-tools-defaults.json:

{
  "Information": [
    "This file provides default values for the deployment wizard inside Visual Studio and the AWS Lambda commands added to the .NET Core CLI.",
    "To learn more about the Lambda commands with the .NET Core CLI execute the following command at the command line in the project root directory.",
    "dotnet lambda help",
    "All the command line options for the Lambda command can be specified in this file."
  ],
  "profile": "default",
  "region": "eu-west-1",
  "configuration": "Release",
  "framework": "netcoreapp3.1",
  "function-runtime": "dotnetcore3.1",
  "function-memory-size": 256,
  "function-timeout": 30,
  "function-handler": "HandleStreamEvent"
}
B bug modullambda-test-tool needs-reproduction

All 7 comments

Is there a chance, that the cause is a PublishTrimmed flag during build? https://docs.microsoft.com/de-de/dotnet/core/whats-new/dotnet-core-3-0#assembly-linking

Sadly not - my project file is pretty ordinary:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
    <AWSProjectType>Lambda</AWSProjectType>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Amazon.Lambda.Core" Version="1.1.0" />
    <PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="1.0.0" />
    <PackageReference Include="Amazon.Lambda.DynamoDBEvents" Version="1.1.0" />
    <PackageReference Include="AWSSDK.DynamoDBv2" Version="3.3.105.14" />
    <PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.7" />
    <PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="3.1.3" />
    <PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="3.1.3" />
    <PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
  </ItemGroup>
</Project>

Apart from some internal nuget pacakges that is like for like.


Just as aa bit of an aside, I did attempt to have a repro of this issue but have been unable to repro outside of this particular project. If there is no obviou solution I could port what I have to a new lambda function and hope for the best there

I am having this same problem with using libraries that have a Microsoft.AspNetCore dependency. I put together a test project. It builds but throws the MissingMethodException when run via the lambda test tool.

[Removed pending employer approval to upload source code]

Would appreciate some insight as we were forced to downgrade our lambda to .NET Core 2.1 in order to continue development. Thank you!

Recently I've faced this issue.

For me it was the usage of Microsoft.Extensions.DependencyInjection.Abstractions in version 3.x that was causing trouble.
Downgrading to version 2.x fixed the issue for me.

For you, it might be another library, but the root cause seems to be the same which is that currently the AWS Libraries compile with a version 2.x reference for Microsoft packages such Microsoft.Extensions.DependencyInjection.Abstractions.

The problem then arises because the AWS Libraries say that those packages work with the transitive dependencies with versions superior or equal to >=2.0.0. But it seems that's not the case.
Introducing a version with a major change actually breaks the application (ex.: 3.x versions), which is turn is actually _fine_ since a major change means that the contracts might be broken, so nothing is wrong there.

I think the best course of action would probably be to gate the transitive dependencies to use versions >=2.0.0 and <3.0.0 on the AWS side.
If someone could validate this it would be really helpful.

It's been a while since I've been able to look at this, but I was finally able to upload a test project.

I am not sure that the problem is with the AWS libraries themselves. The reason is the error ONLY occurs when running the lambda in the test tool. When uploading the same code to a deployed lambda and running it in the cloud, there are no problems.

Any ideas on what might be the problem?

I would have to take the time to dig deeper into it.

But at first glance it might me that the tool has its own set of dependencies that somehow might be conflicting with the app. I would have to check how the assembly resolution is done when the application is attached to the tool to see if my guess is correct (since I believe the tool is what provisions the "_runtime_" while testing).

But then again this is just a wild guess, so take it with a grain of salt.

Was this page helpful?
0 / 5 - 0 ratings