aws / aws-extensions-for-dotnet-cli

Extensions to the dotnet CLI to simplify the process of building and publishing .NET Core applications to AWS services
Apache License 2.0
369 stars 86 forks source link

Optimised layer fail. Dependency issue. #186

Closed kabzit13 closed 1 week ago

kabzit13 commented 2 years ago

Description

dotnet lambda publish-layer command failing when parameter --enable-package-optimization equals true.

... store: Error: Could not load file or assembly 'System.ComponentModel.Annotations, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The located assembly's manifest definition does not match the assembly reference. (0x80131040)

The same set of NuGet packs successfully working on lambda runtime. Layer published successfully if --enable-package-optimization equals false.

Reproduction Steps

Execute command dotnet lambda publish-layer search-common-core --framework netcoreapp3.1 --layer-type runtime-package-store --s3-bucket my-bucket-name --package-manifest ./manifest.xml --enable-package-optimization true

manifest.txt Change extension. Change S3 bucket.

Logs

logs.txt

Environment


This is a :bug: bug-report

ashishdhingra commented 2 years ago

Hi @kabzit13,

Good morning.

Please share the sample code solution (including the .csproj file) for reproducing the issue.

Thanks, Ashish

kabzit13 commented 2 years ago

I am not able to share my project, but attached manifest file should be enought to reproduce an issue. I am not uploading solution to EC2 instance, where I am building layer.

ashishdhingra commented 2 years ago

Hi @kabzit13,

Good afternoon.

I was able to reproduce the issue on Amazon Linux using simple Lambda function project and your manifest file, and then executing the above dotnet lambda publish-layer command on Amazon Linux 2 instance. However, I'm not sure if this is a .NET CLI Lambda extensions issue since the dotnet lambda publish-layer command invokes dotnet store internally and enables package optimization by not adding --skip-optimization to the target command.

I could see that Microsoft.EntityFrameworkCore has a dependency on System.ComponentModel.Annotations. Have you tried posting the question to Microsoft's .NET repository? There is a similar issue reported https://github.com/dotnet/runtime/issues/27975, which might help you to get some lead. Also, could you try removing references to Microsoft.EntityFrameworkCore assemblies from your project/manifest and see if it resolves the issue.

I will try to do some research and if required, have team look into it.

Thanks, Ashish

kabzit13 commented 2 years ago

Hello,

Thanks for your feedback. I have not posted to them.

I have tried to exclude dependencies one by one and found out that there are not only one causing this issue. And not only because of System.ComponentModel.Annotations.

<PackageReference Include="NEST" Version="7.10.1" />
<PackageReference Include="NEST.JsonNetSerializer" Version="7.10.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.7">
    <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    <PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.7" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="5.0.0" />

I will try to raise this issue on dotnet repo.

Maybe you know, are when able to use part of dependencies from layer, and part from the uploaded pack on lambda deploy?

carlin-q-scott commented 2 years ago

This seems to be same issue I reported in #167

ashishdhingra commented 3 weeks ago

@kabzit13 Good morning. Could you please check if this is still reproducible in .NET 6 or later? .NET 3.1 has reached end of life per https://dotnet.microsoft.com/en-us/download/dotnet/3.1. Based on discussion with the team, we could investigate the issue if it is reproducible in .NET6+.

Thanks, Ashish

github-actions[bot] commented 1 week ago

This issue has not received a response in 5 days. If you want to keep this issue open, please just leave a comment below and auto-close will be canceled.