Skip to content

Add compile-time diagnostic for unsupported [FromHeader] parameter types - #2627

Open
harshbhx wants to merge 1 commit into
aws:masterfrom
harshbhx:fix/1686-fromheader-unsupported-type
Open

harshbhx wants to merge 1 commit into
aws:masterfrom
harshbhx:fix/1686-fromheader-unsupported-type

Conversation

@harshbhx

Copy link
Copy Markdown

Issue #, if available: #1686

Description of changes:

[FromHeader] parameters are bound with Convert.ChangeType, so a type like Guid or a user-defined type compiles fine and then throws InvalidCastException at runtime. [FromQuery] already rejects these at build time (AWSLambda0109). As discussed on the issue, this adds the same check for headers as an interim step; supporting custom types (e.g. IParsable<T>) is left for a separate feature.

  • New diagnostic AWSLambda0146 ("Unsupported Header Parameter Type"), reported when a [FromHeader] parameter is not a primitive .NET type or an enumerable of one.
  • Applied to API Gateway functions, Lambda authorizer functions, and ALB functions (ALB.FromHeaderAttribute).
  • Registered the rule in AnalyzerReleases.Unshipped.md.
  • Added a change file under .autover/changes/.
  • Test: ComplexHeaderParameters_AreNotSupported (mirrors the existing ComplexQueryParameters_AreNotSupported) using a Guid header parameter.

Testing: ran Amazon.Lambda.Annotations.SourceGenerators.Tests (SourceGeneratorTests, ALB and authorizer binding tests) on GitHub Actions in my fork for net8.0 and net10.0: 149 passed, 0 failed per target. The repo's own AWS CI needs credentials, so it was not run. The repo's existing test apps only use primitive header types, so nothing existing should be affected.

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

@harshbhx
harshbhx requested review from a team as code owners November 28, 2026 20:39
@harshbhx
harshbhx requested review from normj and siddsriv November 28, 2026 20:39

This branch has not been deployed

No deployments
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.

1 participant