Skip to content

test: keep runtime reflection confined to the JIT-only fallback - #73

Merged
Blind-Striker merged 2 commits into
aot/internal-docs-3.0.0from
aot/reflection-free-test
Oct 23, 2026
Merged

Blind-Striker merged 2 commits into
aot/internal-docs-3.0.0from
aot/reflection-free-test

Conversation

@Blind-Striker

@Blind-Striker Blind-Striker commented Oct 23, 2026 •

Copy link
Copy Markdown
Member

Stack (review bottom-up, merge as one stack): #62 base, #66 the #63 fix, #67 Native AOT test lane, #68 static-factory generic path, #70 slim generator, #71 public docs, #72 internal docs and 3.0.0, #73 reflection-free test, #74 package consumer in CI, #75 convention clean-up, #76 service catalog refresh.

Goal of the stack: 3.0.0, where existing consumers upgrade without code changes, both packages support Native AOT on net10.0/net11.0, and the libraries use no runtime reflection for types the compiler can see (a JIT-only fallback covers the rest).

This PR

ReflectionFreeAssemblyTests (Libraries_Should_Call_Runtime_Reflection_Only_From_RequiresUnreferencedCode_Methods) decodes the IL of LocalStack.Client and LocalStack.Client.Extensions (net10.0/net11.0). It fails if a runtime-reflection API (member lookup, Field/PropertyInfo access, Invoke, Activator.CreateInstance, Type.GetType(string), Assembly.GetType, Emit, Expression.Compile) is called outside a [RequiresUnreferencedCode] method, that is, outside the fallback that trimmed and AOT apps remove. It also requires the fallback's own calls to be found, so an empty scan cannot pass.

Verification

Green on net10/net11 (Extensions 63). Red check: adding a trim-safe typeof(Session).GetConstructors() to the Session constructor made it fail with LocalStack.Client.Session..ctor -> System.Type.GetConstructors.

@Blind-Striker
Blind-Striker added this pull request to stack #69 October 23, 2026 13:33
@github-actions

Copy link
Copy Markdown

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

ReflectionFreeAssemblyTests decodes the IL of LocalStack.Client and
LocalStack.Client.Extensions (net10.0/net11.0) and fails when a runtime
reflection API (member lookup, FieldInfo/PropertyInfo access, Invoke,
Activator.CreateInstance, Type.GetType(string), Assembly.GetType,
Reflection.Emit, Expression.Compile) is called outside a method marked
[RequiresUnreferencedCode], i.e. outside the fallback that trimmed and
Native AOT apps remove. It also requires that the fallback's allowed
calls are found, so an empty scan cannot pass.

Checked red: a trim-safe typeof(Session).GetConstructors() added to the
Session constructor fails the test with
"LocalStack.Client.Session..ctor -> System.Type.GetConstructors".
@Blind-Striker
Blind-Striker force-pushed the aot/reflection-free-test branch from 06694d4 to b5fa969 Compare October 23, 2026 21:13
@Blind-Striker
Blind-Striker marked this pull request as ready for review October 23, 2026 21:55
@Blind-Striker
Blind-Striker merged commit 49573c2 into master Oct 23, 2026
19 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.

1 participant