Skip to content

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

Merged
dscpinheiro merged 1 commit into
aws:masterfrom
harshbhx:fix/1686-fromheader-unsupported-type
Dec 2, 2026
Merged

dscpinheiro merged 1 commit into
aws:masterfrom
harshbhx:fix/1686-fromheader-unsupported-type

Conversation

@harshbhx

Copy link
Copy Markdown
Contributor

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
@dscpinheiro
dscpinheiro requested review from dscpinheiro and removed request for siddsriv December 1, 2026 23:18
@dscpinheiro
dscpinheiro merged commit 813d199 into aws:master Dec 2, 2026
4 of 6 checks passed
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.

3 participants