12

I create a new AWS Lambda .NET Core 3.1 project, then run it using AWS Lambda Test Tools, then I get this page as expected:

enter image description here

However, if I install one of these packages:

Microsoft.EntityFrameworkCore.SqlServer

Microsoft.Data.SqlClient

When I run, I get this error and the test page won't open:

AWS .NET Core 3.1 Mock Lambda Test Tool (0.10.0)
Unknown error occurred causing process exit: Dependency resolution failed for component C:\Users\siri\repos\bolao-futebol\website-core\AWSLambda1\bin\Debug\netcoreapp3.1\AWSLambda1.dll with error code -2147450740. Detailed error: Error:
An assembly specified in the application dependencies manifest (AWSLambda1.deps.json) was not found:
package: 'runtime.win-x64.runtime.native.System.Data.SqlClient.sni', version: '4.4.0'
path: 'runtimes/win-x64/native/sni.dll'

at System.Runtime.Loader.AssemblyDependencyResolver..ctor(String componentAssemblyPath)
at Amazon.Lambda.TestTool.Runtime.LambdaAssemblyLoadContext..ctor(String lambdaPath) in C:\codebuild\tmp\output\src142363207\src\Tools\LambdaTestTool\src\Amazon.Lambda.TestTool\Runtime\LambdaAssemblyLoadContext.cs:line 28
at Amazon.Lambda.TestTool.Runtime.LocalLambdaRuntime.Initialize(String directory, IAWSService awsService) in C:\codebuild\tmp\output\src142363207\src\Tools\LambdaTestTool\src\Amazon.Lambda.TestTool\Runtime\LocalLambdaRuntime.cs:line 71
at Amazon.Lambda.TestTool.Runtime.LocalLambdaRuntime.Initialize(String directory) in C:\codebuild\tmp\output\src142363207\src\Tools\LambdaTestTool\src\Amazon.Lambda.TestTool\Runtime\LocalLambdaRuntime.cs:line 46
at Amazon.Lambda.TestTool.TestToolStartup.Startup(String productName, Action`2 uiStartup, String[] args, RunConfiguration runConfiguration) in C:\codebuild\tmp\output\src142363207\src\Tools\LambdaTestTool\src\Amazon.Lambda.TestTool\TestToolStartup.cs:line 77

enter image description here

I have a .NET Core 2.1 Lambda project with this package and it works fine, it only fails in .NET Core 3.1.

Below is my .csproj in case anyone wants to give a try.

<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.SQSEvents" Version="1.1.0" />
    <PackageReference Include="Amazon.Lambda.AspNetCoreServer" Version="5.0.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.0" />
  </ItemGroup>
</Project>

This works fine deployed on AWS Lambda, it only fails running it locally with the Mock Tools.

Removing Microsoft.EntityFrameworkCore.SqlServer makes it work again.


This was also posted in github a while ago, I'm hoping someone else ran into this and has a fix.

Community
  • 1
  • 1
Alisson Reinaldo Silva
  • 10,009
  • 5
  • 65
  • 83

3 Answers3

32

Could you try and experiment for me and in your csproj file add the property CopyLocalLockFileAssemblies with a value of true and see if that changes your behavior?

Here is a full csproj file example.

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
    <AWSProjectType>Lambda</AWSProjectType>
    <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Amazon.Lambda.Core" Version="1.1.0" />
    <PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="1.0.0" />
    <PackageReference Include="System.Data.SqlClient" Version="4.8.1" />
  </ItemGroup>
</Project>
Norm Johanson
  • 2,964
  • 14
  • 13
  • 2
    Yep, adding `CopyLocalLockFileAssemblies` works. My understanding is that [this will add all nuget package DLL's to the output (bin) folder](https://stackoverflow.com/questions/43837638/how-do-i-get-net-core-projects-to-copy-nuget-references-to-the-build-output), but it's still unclear to me why this is an issue only with `System.Data.SqlClient` and not other packages. – Alisson Reinaldo Silva Apr 23 '20 at 22:15
  • Amazon's own project templates now do this by default, with the comment "This property makes the build directory similar to a publish directory and helps the AWS .NET Lambda Mock Test Tool find project dependencies." – qid Jan 06 '21 at 17:04
5

I had the same issue when I was trying to deploy my AWS lambda function to AWS using Terraform.

Adding this property to my lambda functions .csproj file fixed the issue. It allows all the nuget package dependencies, required by the plugin, to be copied to the output directory -

<PropertyGroup>
  <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>
Pushpak
  • 301
  • 3
  • 6
2

I had the same issue, but in my case I had the tool installed but somehaow it got broken, so I have to uninstall it, deleting the file "C:\Users\{USERNAME}\.dotnet\tools\dotnet-lambda-test-tool-3.1.exe"

Then I could reinstall it running "dotnet tool install -g Amazon.Lambda.TestTool-3.1"

Javier Pazos
  • 119
  • 2
  • 6