Fix ReflectionTypeLoadException for ILambdaResponseStream when bundli…#2431
Open
jonathanbcsouza wants to merge 1 commit into
Open
Fix ReflectionTypeLoadException for ILambdaResponseStream when bundli…#2431jonathanbcsouza wants to merge 1 commit into
jonathanbcsouza wants to merge 1 commit into
Conversation
…ng older Amazon.Lambda.Core Replace direct ILambdaResponseStream interface implementation (ImplLambdaResponseStream) with DispatchProxy-based dynamic implementation. This prevents GetTypes() on the Amazon.Lambda.RuntimeSupport assembly from triggering TypeLoadException when customers bundle Amazon.Lambda.Core < 3.0.0 (which lacks the interface type). The DispatchProxy approach generates the interface implementation at runtime only when the loaded Amazon.Lambda.Core has the ResponseStreaming types. If the types are absent, InitializeCore() returns gracefully without error. Fixes aws#2430
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue #, if available:
#2430
Description of changes:
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 older DLL in/var/tasktakes assembly resolution precedence over the runtime's copy in/var/runtime. Any code callingGetTypes()on the RuntimeSupport assembly triggersReflectionTypeLoadExceptionbecause .NET cannot resolveILambdaResponseStreamfrom the loaded older Core.This breaks all .NET 8 Zip Lambda functions on Auto runtime management that use ASP.NET Core hosting, AutoMapper, MediatR, or any DI framework that scans types at startup. May also affect
dotnet:10.v36and any any .NET managed runtime that shipped the response streaming RuntimeSupport.Fix: Replace the direct
ILambdaResponseStreaminterface implementation (ImplLambdaResponseStream) with aDispatchProxy-based dynamic implementation. No type in the RuntimeSupport assembly directly referencesILambdaResponseStreamat compile time, soGetTypes()no longer triggers the type load. The proxy is only created at runtime after confirming the interface exists in the loadedAmazon.Lambda.Core.Changes:
ResponseStreamLambdaCoreInitializerIsolated.cs: RemovedImplLambdaResponseStreamnested class. Added reflection-based initialization withDispatchProxyto dynamically implementILambdaResponseStreamwithout a static type reference.ResponseStreamProxy: NewDispatchProxysubclass that forwards interface calls toResponseStream.TestImplLambdaResponseStream.cs: Test-only helper replacing the removed production class in unit tests.LambdaResponseStreamingCoreTests.cs: Updated to useTestImplLambdaResponseStream.Testing:
NativeAOTTestsrequiring .NET 9/10 SDK, unrelated to this change)/var/runtime/which is immutable outside the Lambda team's build pipeline)