Skip to content

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

@wdolek

Description

@wdolek

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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions