Skip to content

Fix type load issue due to Lambda Response Streaming.#2435

Merged
normj merged 9 commits into
masterfrom
normj/fix-stream-load-issue
Jun 22, 2026
Merged

Fix type load issue due to Lambda Response Streaming.#2435
normj merged 9 commits into
masterfrom
normj/fix-stream-load-issue

Conversation

@normj

@normj normj commented Jun 22, 2026

Copy link
Copy Markdown
Member

Issue #, if available:
#2430

Description of changes:
As part of the work to add Lambda Response Streaming a new internal type was added to RuntimeSupport that implemented a new interface in Amazon.Lambda.Core. The challenge is at runtime we might have an older version of Amazon.Lambda.Core that doesn't have the interface. Access to the new internal type in RuntimeSupport was covered in defensive checks so that if the interface did not exist at runtime the code would silently ignore the situation and continue. This was fine because if the interface didn't exist then they wouldn't be using Lambda Response Streaming.

The problem is if the user used a framework that scanned all types across assemblies like the following code

var allTypes = AppDomain.CurrentDomain.GetAssemblies()
    .SelectMany(a => a.GetTypes())
    .Where(t => t.IsClass && !t.IsAbstract)
    .ToList();

That would fail because skips RuntimeSupport's defensive checks and attempts to load the internal type from RuntimeSupport. Since the interface that the type declares it implements doesn't exist the runtime fails to load and then throws an exception.

This fix address the issue by no longer having a type in RuntimeSupport that has the interface in it's inheritance hierarchy. Instead I moved the implementation to Amazon.Lambda.Core and then pass through internal channels the collection of delegates from RuntimeSupport to Core so that the implementation in Core can forward on the logic into RuntimeSupport.

Testing
Updated the tests and they were successful. I also recreated the customer issue by deploying with specific assembly versions and not NuGet packages using the executable programming model. Once I had recreated the failure I swapped out only this version of RuntimeSupport keeping the same version of Core that caused the problem and the Lambda function ran correctly.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses a runtime ReflectionTypeLoadException triggered when customer frameworks scan all loaded types (Assembly.GetTypes()), by removing the problematic response-streaming interface implementation from Amazon.Lambda.RuntimeSupport and relocating the implementation/bridge into Amazon.Lambda.Core.

Changes:

  • Moves the ILambdaResponseStream implementation into Amazon.Lambda.Core and switches RuntimeSupport to pass a delegate-based bridge object.
  • Updates RuntimeSupport unit tests to construct the Core-side implementation via shared helpers.
  • Adds AutoVer change metadata for patch releases of Core and RuntimeSupport.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
Libraries/test/Amazon.Lambda.RuntimeSupport.Tests/Amazon.Lambda.RuntimeSupport.UnitTests/LambdaResponseStreamingCoreTests.cs Updates tests to use the new helper for creating the Core-side response stream implementation.
Libraries/test/Amazon.Lambda.RuntimeSupport.Tests/Amazon.Lambda.RuntimeSupport.UnitTests/LambdaBootstrapMultiConcurrencyTests.cs Removes an unused counter variable/comment in the starvation exploration test.
Libraries/test/Amazon.Lambda.RuntimeSupport.Tests/Amazon.Lambda.RuntimeSupport.UnitTests/Common.cs Adds a helper that constructs the Core-side ImplLambdaResponseStream using delegate forwarding.
Libraries/src/Amazon.Lambda.RuntimeSupport/Bootstrap/ResponseStreaming/ResponseStreamLambdaCoreInitializerIsolated.cs Reworks initialization to create the Core-side implementation and register the factory.
Libraries/src/Amazon.Lambda.Core/ResponseStreaming/LambdaResponseStreamFactory.cs Adds new using directives (currently unused).
Libraries/src/Amazon.Lambda.Core/ResponseStreaming/ImplLambdaResponseStream.cs Introduces a new internal Core-side implementation that forwards to delegate callbacks.
.autover/changes/f6d458e7-d276-40d2-b1ab-d0c4327e396f.json Adds patch changelog entries for Core and RuntimeSupport.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread Libraries/src/Amazon.Lambda.Core/ResponseStreaming/LambdaResponseStreamFactory.cs Outdated
Comment thread .autover/changes/f6d458e7-d276-40d2-b1ab-d0c4327e396f.json Outdated
normj and others added 7 commits June 22, 2026 11:02
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@normj
normj merged commit 4ed2253 into master Jun 22, 2026
9 checks passed
@normj normj mentioned this pull request Jun 22, 2026
@dscpinheiro
dscpinheiro deleted the normj/fix-stream-load-issue branch June 29, 2026 02:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants