aws / aws-lambda-dotnet

Libraries, samples and tools to help .NET Core developers develop AWS Lambda functions.
Apache License 2.0
1.58k stars 478 forks source link

.NET Core 3.1 - Dependency resolution failed for component #617

Closed AlissonRS closed 4 years ago

AlissonRS commented 4 years ago

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:

image

However, if I install this package:

Microsoft.EntityFrameworkCore.SqlServer

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 Press any key to exit

image

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

You can find below my .csproj in case you want 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>

Just removing Microsoft.EntityFrameworkCore.SqlServer makes it work again.

jaknor commented 4 years ago

I am seeing the same behavior.

@AlissonRS did you try and deploy your lambda? If so, did it work as expected?

nishantmadaan commented 4 years ago

@jaknor It works as expected after you deploy the lambda.

I am seeing the same behavior.

@AlissonRS did you try and deploy your lambda? If so, did it work as expected?

aeustachon commented 4 years ago

receiving same error after installing a package

lambda does work as intended when deployed, only get this error when trying to run the mock lambda test tool (.net core 3.1)

RNavaneethKumar commented 4 years ago

Facing a similar issue. Good that the lambda works fine when deployed. However without debugging, there is no way forward. Is there a workaround fix for this in the meantime?

labrev commented 4 years ago

I got the same issue but for just installing the Microsoft.Data.SqlClient package. My function does work when deployed though just like everyone else is saying. The fact that the Lambda function works when deployed makes me think this is isolated to the Mock Lambda Test Tool.

AlissonRS commented 4 years ago

I just created a question in Stack Overflow, I'm hoping someone had this issue and found a solution.

https://stackoverflow.com/questions/61355168/net-core-3-1-dependency-resolution-failed-for-component-aws-mock-lambda-tes

labrev commented 4 years ago

See #639 Updating the .csproj file worked per @normj

I added <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies> in the PropertyGroup.

AlissonRS commented 4 years ago

That's right, and @normj just answered the question on Stack Overflow.

Here is a full working .csproj:

<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>