question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

.NET Core 3.1 runtime incompatibility with Amazon.Lambda.Logging.AspNetCore 3.0.0

See original GitHub issue

We are in process of migrating our Lambdas to .NET Core 3.1 and I just found one incompatibility when using Amazon.Lambda.Logging.AspNetCore version 3.0.0.

We are using logger scopes (to decorate all log messages with certain value).

Exception being thrown:

Could not load type 'Microsoft.Extensions.Logging.Abstractions.Internal.NullScope' from assembly 'Microsoft.Extensions.Logging.Abstractions, Version=3.1.4.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.: TypeLoadException
   at Microsoft.Extensions.Logging.Logger.BeginScope[TState](TState state)
   at Microsoft.Extensions.Logging.Logger`1.Microsoft.Extensions.Logging.ILogger.BeginScope[TState](TState state)
   at Acme.Common.Extensions.LoggerExtensions.BeginScopeWithInformationalVersion(ILogger logger, Assembly assembly) in /builds/Acme.Common/Extensions/LoggerExtensions.cs:line 19
   at Acme.Common.Extensions.LoggerExtensions.BeginScopeWithInformationalVersion[T](ILogger logger) in /builds/Acme.Common/Extensions/LoggerExtensions.cs:line 10
   at Acme.Le.LeHandler.Handler(Dictionary`2 input, ILambdaContext context) in /builds/Acme.LeHandler/LeHandler.cs:line 89
   at lambda_method(Closure , Stream , Stream , LambdaContextInternal )

Our csproj looks like this:

<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.Logging.AspNetCore" Version="3.0.0" />
    <PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.0.1" />
    <PackageReference Include="Amazon.Lambda.SQSEvents" Version="1.1.0" />
    <PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.4" />
    <PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="3.1.4" />
    <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.1.4" />
    <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.4" />
    <PackageReference Include="Microsoft.Extensions.Http" Version="3.1.4" />
    <PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="3.1.4" />
  </ItemGroup>

  // ...

</Project>

I’m suspecting (and actually verified after dotnet publish) that there’s version clash, since Amazon.Lambda.Logging.AspNetCore is referencing:

  <ItemGroup>
    <PackageReference Include="Microsoft.Extensions.Logging" Version="2.1.0" />
    <PackageReference Include="Microsoft.Extensions.Configuration" Version="2.1.0" />
    <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.1.0" />
  </ItemGroup>

One of breaking change between 2.1 and 3.1 is that NullScope is now internal.

Proposed solution: I suggest to use version range for those dependencies like this:

  <ItemGroup>
    <PackageReference Include="Microsoft.Extensions.Logging" Version="[3.1,3.2)" />
    <PackageReference Include="Microsoft.Extensions.Configuration" Version="[3.1,3.2)" />
    <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="[3.1,3.2)" />
  </ItemGroup>

I don’t expect any impact on functionality (haven’t tried yet), I can prepare PR - if you agree with my suggestion.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
normjcommented, May 28, 2020

@wdolek Thanks for reporting the issue. We are working on getting the fix out. I’m going to transfer the issue to the Lambda repository which is where the code lives for Amazon.Lambda.Logging.AspNetCore

0reactions
github-actions[bot]commented, Dec 9, 2020

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.

Read more comments on GitHub >

github_iconTop Results From Across the Web

NET Core 3.0 on Lambda with AWS Lambda's Custom Runtime
One of our popular features is to run ASP.NET Core applications using .NET Core and Lambda. This is possible with the Amazon.Lambda.
Read more >
AWS Lambda now supports .NET Core 3.1
NET Core 3.1, update your code to be compatible with .NET Core 3.1 and Amazon Linux 2, and then update the function runtime...
Read more >
c# - .NET Core 3.1 AWS Lambda Could not load file or ...
Migrating to .NET 6 To migrate existing .NET Lambda functions to the new .NET 6 runtime: Open the csproj or fsproj file.
Read more >
Announcing AWS Lambda support for .NET Core 3.1
From today, you can develop AWS Lambda functions using .NET Core 3.1. You can deploy to Lambda by setting the runtime parameter value...
Read more >
Deploying to AWS Lambda from Visual Studio Team ...
I have created a .Net Core 2.0 Web API and am trying to deploy it using Visual Studio Team Services and the AWS...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found