aws / aws-lambda-dotnet

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

System.IO.FileLoadException: Could not load file or assembly Microsoft.AspNetCore.Diagnostics.Abstractions, Version=6.0.0.0 #1184

Closed starkcolin closed 2 years ago

starkcolin commented 2 years ago

Describe the bug

I'm seeing frequent Lambda errors where the assembly Microsoft.AspNetCore.Diagnostics.Abstractions cannot be loaded. This assembly is part of the ASP.NET Core runtime, so it should always be present.

Using Lambda .NET 6 runtime with ASP.NET Core

Expected Behavior

Assembly is loaded, no exception is thrown.

Current Behavior

Example stacktrace:

System.IO.FileLoadException: Could not load file or assembly 'Microsoft.AspNetCore.Diagnostics.Abstractions, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. An internal error occurred.(0x8007054F) File name: 'Microsoft.AspNetCore.Diagnostics.Abstractions, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.HandleException(HttpContext context, ExceptionDispatchInfo edi) at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine) at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.HandleException(HttpContext context, ExceptionDispatchInfo edi) at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.<Invoke>g__Awaited\|6_0(ExceptionHandlerMiddleware middleware, HttpContext context, Task task) at Serilog.AspNetCore.RequestLoggingMiddleware.Invoke(HttpContext httpContext)

Reproduction Steps

Not sure exactly what triggers it, but I believe it's related to the exception middleware in ASP.NET Core.

Possible Solution

Assembly is not present in the Lambda runtime.

Additional Information/Context

No response

AWS .NET SDK and/or Package version used

Amazon.Lambda.AspNetCoreServer version 7.2.0

Targeted .NET Platform

.NET 6

Operating System and version

Lambda

ashishdhingra commented 2 years ago

Hi @starkcolin,

Good afternoon.

Thanks for reporting the issue. Would it be possible for you to share the minimal code solution/project to reproduce the issue? I just want to make sure that we have almost the same environment/configuration.

Regards, Ashish

starkcolin commented 2 years ago

Not easily unfortunately. The code is confidential, and it would take a pretty substantial effort to create a new project and attempt to reproduce it there. I've provided you with the ZIP file containing the code that the Lambda function is running from, with all proprietary code removed. The packages.lock.json file will also show what the dependencies are. Not sure how much help that is, so let me know if there's anything else I can provide you. LambdaEnvironment.zip

ashishdhingra commented 2 years ago

Not easily unfortunately. The code is confidential, and it would take a pretty substantial effort to create a new project and attempt to reproduce it there. I've provided you with the ZIP file containing the code that the Lambda function is running from, with all proprietary code removed. The packages.lock.json file will also show what the dependencies are. Not sure how much help that is, so let me know if there's anything else I can provide you. LambdaEnvironment.zip

@starkcolin Thanks for the reply. Could you please share the package references from .csproj file? This would make it easier to develop simple Serverless ASP.NET Web API application using the packages in your environment.

starkcolin commented 2 years ago

The csproj of the project for the Lambda function, as well as the proprietary libraries it references are included in the ZIP file below. This should be easily to use than the packages.lock.json file.

csproj files.zip

ashishdhingra commented 2 years ago

The csproj of the project for the Lambda function, as well as the proprietary libraries it references are included in the ZIP file below. This should be easily to use than the packages.lock.json file.

@starkcolin Unfortunately I'm unable to reproduce the issue.

Here's my .csproj file for your reference:

<Project Sdk="Microsoft.NET.Sdk.Web">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net6.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
    <AWSProjectType>Lambda</AWSProjectType>
    <!-- This property makes the build directory similar to a publish directory and helps the AWS .NET Lambda Mock Test Tool find project dependencies. -->
    <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
    <!-- Generate ready to run images during publishing to improve cold start time. -->
    <PublishReadyToRun>true</PublishReadyToRun>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Amazon.AspNetCore.DataProtection.SSM" Version="2.1.0" />
    <PackageReference Include="Amazon.Extensions.Configuration.SystemsManager" Version="3.0.0" />
    <PackageReference Include="Amazon.Lambda.AspNetCoreServer" Version="7.2.0" />
    <PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="11.0.0" />
    <PackageReference Include="AWSSDK.CloudWatchLogs" Version="3.7.2.53" />
    <PackageReference Include="AWSSDK.Extensions.NETCore.Setup" Version="3.7.2" />
    <PackageReference Include="AWSSDK.S3" Version="3.7.9.3" />
    <PackageReference Include="AWSSDK.SecretsManager" Version="3.7.2.43" />
    <PackageReference Include="AWSSDK.SimpleSystemsManagement" Version="3.7.17.5" />
    <PackageReference Include="FluentValidation.AspNetCore" Version="11.0.1" />
    <PackageReference Include="Kralizek.Extensions.Configuration.AWSSecretsManager" Version="1.6.3" />
    <PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.8" />
    <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.5" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="6.0.5" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="5.0.0" />
    <PackageReference Include="Microsoft.Extensions.PlatformAbstractions" Version="1.1.0" />
    <PackageReference Include="Microsoft.Graph" Version="4.29.0" />
    <PackageReference Include="Microsoft.SourceLink.AzureRepos.Git" Version="1.1.1">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Nerdbank.GitVersioning" Version="3.5.104" PrivateAssets="All" />
    <PackageReference Include="Roslynator.Analyzers" Version="4.1.0">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Sendgrid" Version="9.28.0" />
    <PackageReference Include="Serilog.AspNetCore" Version="5.0.0" />
    <PackageReference Include="Serilog.Sinks.AwsCloudWatch" Version="4.0.171" />
    <PackageReference Include="Sodium.Core" Version="1.2.3" />
    <PackageReference Include="StyleCop.Analyzers.Unstable" Version="1.2.0.435">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Swashbuckle.AspNetCore" Version="6.3.1" />
    <PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="6.3.1" />
    <PackageReference Include="Swashbuckle.AspNetCore.Newtonsoft" Version="6.3.1" />
    <PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.17.0" />
  </ItemGroup>
</Project>

Not sure if the error you notice are due to dependent projects. I'm unsure what to advise since we do not have a reproduction.

Thanks, Ashish

starkcolin commented 2 years ago

OK I'll try to follow up and get a working repro project, but it will probably take some time. If the issue stops occurring in the meantime, then I'll report that back as well and close the issue.

github-actions[bot] commented 2 years 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.

SamRD2 commented 2 years ago

I have this issue also on .NET 6.

And entity framework latest version don't seem to load.