You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The dotnet:8.v88 managed runtime ships Amazon.Lambda.RuntimeSupport 2.1.1.0, which contains ImplLambdaResponseStream : ILambdaResponseStream in ResponseStreamLambdaCoreInitializerIsolated.cs. When a function bundles Amazon.Lambda.Core < 3.0.0 (which dotnet publish does by default), the DLL in /var/task takes assembly resolution precedence over the runtime's copy in /var/runtime. The older DLL lacks ILambdaResponseStream.
Any code that calls Assembly.GetTypes() on the Amazon.Lambda.RuntimeSupport assembly (standard in ASP.NET Core DI, AutoMapper, MediatR) throws ReflectionTypeLoadException at INIT. The function never starts.
GetTypes() fails on the Amazon.Lambda.RuntimeSupport assembly (not Amazon.Lambda.Core) because ImplLambdaResponseStream implements ILambdaResponseStream. .NET tries to resolve the interface from the loaded Amazon.Lambda.Core (the older copy from /var/task), which doesn't have it.
The existing try/catch in LambdaBootstrap.cs:244 protects InitializeCore() but does not protect downstream code scanning RuntimeSupport's types.
Regression Issue
Select this option if this issue appears to be a regression.
Expected Behavior
Functions bundling older Amazon.Lambda.Core (< 3.0.0) should continue to initialize successfully on dotnet:8.v88, as they did on dotnet:8.v84. The runtime should be backward compatible with existing deployment packages.
Current Behavior
Functions fail at INIT with:
INIT_START Runtime Version: dotnet:8.v88
INIT_REPORT Init Duration: 443.99 ms Phase: init Status: error Error Type: Runtime.Unknown
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
---> System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types.
Could not load type 'Amazon.Lambda.Core.ResponseStreaming.ILambdaResponseStream'
from assembly 'Amazon.Lambda.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=885c28607f98e604'.
at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
at Startup.ConfigureServices(IServiceCollection services)
at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.UseStartup(...)
at Microsoft.Extensions.Hosting.HostBuilder.Build()
at Amazon.Lambda.AspNetCoreServer.AbstractAspNetCoreFunction`2.Start()
at Amazon.Lambda.RuntimeSupport.Bootstrap.UserCodeLoader.Init(...) UserCodeLoader.cs:140
at Amazon.Lambda.RuntimeSupport.LambdaBootstrap.InitializeAsync() LambdaBootstrap.cs:358
Result on v88: INIT crash (ReflectionTypeLoadException)
Result on v84 (pinned via put-runtime-management-config): INIT succeeds
Possible Solution
Remove the direct ILambdaResponseStream interface implementation from the Amazon.Lambda.RuntimeSupport assembly metadata. Use reflection-based initialization in ResponseStreamLambdaCoreInitializerIsolated.cs so no type in RuntimeSupport directly references ILambdaResponseStream, preventing GetTypes() from triggering the type load.
Alternatively, move ImplLambdaResponseStream to a separate assembly that is not subject to GetTypes() scanning by customer code.
Describe the bug
The
dotnet:8.v88managed runtime shipsAmazon.Lambda.RuntimeSupport2.1.1.0, which containsImplLambdaResponseStream : ILambdaResponseStreaminResponseStreamLambdaCoreInitializerIsolated.cs. When a function bundlesAmazon.Lambda.Core< 3.0.0 (whichdotnet publishdoes by default), the DLL in/var/tasktakes assembly resolution precedence over the runtime's copy in/var/runtime. The older DLL lacksILambdaResponseStream.Any code that calls
Assembly.GetTypes()on theAmazon.Lambda.RuntimeSupportassembly (standard in ASP.NET Core DI, AutoMapper, MediatR) throwsReflectionTypeLoadExceptionat INIT. The function never starts.GetTypes()fails on theAmazon.Lambda.RuntimeSupportassembly (notAmazon.Lambda.Core) becauseImplLambdaResponseStreamimplementsILambdaResponseStream. .NET tries to resolve the interface from the loadedAmazon.Lambda.Core(the older copy from/var/task), which doesn't have it.The existing
try/catchinLambdaBootstrap.cs:244protectsInitializeCore()but does not protect downstream code scanning RuntimeSupport's types.Regression Issue
Expected Behavior
Functions bundling older
Amazon.Lambda.Core(< 3.0.0) should continue to initialize successfully ondotnet:8.v88, as they did ondotnet:8.v84. The runtime should be backward compatible with existing deployment packages.Current Behavior
Functions fail at INIT with:
Reproduction Steps
Function.cs:ReprodFunction.csproj:Result on v88: INIT crash (ReflectionTypeLoadException)
Result on v84 (pinned via
put-runtime-management-config): INIT succeedsPossible Solution
Remove the direct
ILambdaResponseStreaminterface implementation from theAmazon.Lambda.RuntimeSupportassembly metadata. Use reflection-based initialization inResponseStreamLambdaCoreInitializerIsolated.csso no type in RuntimeSupport directly referencesILambdaResponseStream, preventingGetTypes()from triggering the type load.Alternatively, move
ImplLambdaResponseStreamto a separate assembly that is not subject toGetTypes()scanning by customer code.Additional Information/Context
dotnet publishbundlesAmazon.Lambda.Core.dllby default, so virtually every .NET 8 Zip Lambda has itAmazon.Lambda.Coreto >= 3.0.0AWS .NET SDK and/or Package version used
Targeted .NET Platform
.NET 8
Operating System and version
Amazon Linux 2023