Skip to content

[release/10.0] Fix Native AOT-incompatible reflection in CalendarTestBase#126817

Open
Copilot wants to merge 2 commits intorelease/10.0from
copilot/fix-japanese-calendar-tests
Open

[release/10.0] Fix Native AOT-incompatible reflection in CalendarTestBase#126817
Copilot wants to merge 2 commits intorelease/10.0from
copilot/fix-japanese-calendar-tests

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 13, 2026

Change #122373 broke native AOT testing because it introduced trimming incompatible code into a test.

/cc @MichalStrehovsky

Customer Impact

  • Customer reported
  • Found internally

Test only change. We broke release/10.0 using a release/10.0-only change.

Regression

  • Yes
  • No

Testing

Outerloop run.

Risk

Low. Test only.

IMPORTANT: If this backport is for a servicing release, please verify that:

  • For .NET 8 and .NET 9: The PR target branch is release/X.0-staging, not release/X.0.
  • For .NET 10+: The PR target branch is release/X.0 (no -staging suffix).

Package authoring no longer needed in .NET 9

IMPORTANT: Starting with .NET 9, you no longer need to edit a NuGet package's csproj to enable building and bump the version.
Keep in mind that we still need package authoring in .NET 8 and older versions.

Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/a684b399-ef09-407d-8de5-9e4680d4f736

Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot April 13, 2026 01:01
Copilot AI changed the title [WIP] Fix Japanese calendar tests failing due to null reference exception Fix Native AOT-incompatible reflection in CalendarTestBase Apr 13, 2026
@dotnet-policy-service
Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/area-system-globalization
See info in area-owners.md if you want to be subscribed.

@MichalStrehovsky
Copy link
Copy Markdown
Member

/azp run runtime-nativeaot-outerloop

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@MichalStrehovsky MichalStrehovsky changed the title Fix Native AOT-incompatible reflection in CalendarTestBase [release/10.0] Fix Native AOT-incompatible reflection in CalendarTestBase Apr 13, 2026
@MichalStrehovsky MichalStrehovsky marked this pull request as ready for review April 13, 2026 11:37
Copilot AI review requested due to automatic review settings April 13, 2026 11:37
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 aims to restore NativeAOT test compatibility by adjusting reflection usage in the Japanese calendar test infrastructure (CalendarTestBase) on release/10.0, after a prior change introduced trimming/AOT-incompatible reflection patterns.

Changes:

  • Reworks reflection used to compute the ICU-specific JapaneseCalendar minimum supported date (era ticks) to be more NativeAOT-friendly.

Comment on lines +83 to +84
object[] eraInfo = (object[])typeof(JapaneseCalendar).GetMethod("GetEraInfo", BindingFlags.NonPublic | BindingFlags.Static)!.Invoke(null, null)!;
Type eraInfoType = Type.GetType("System.Globalization.EraInfo, System.Private.CoreLib")!;
Copy link

Copilot AI Apr 13, 2026

Choose a reason for hiding this comment

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

Type.GetType(string) is annotated with RequiresUnreferencedCode on CoreCLR, so this line will produce trimming/AOT analyzer warnings (and likely fail NativeAOT test builds). Consider avoiding Type.GetType(...) here; you can obtain the EraInfo element type via the reflected GetEraInfo method signature (e.g., from MethodInfo.ReturnType.GetElementType()), which avoids string-based type lookup and the RUC annotation.

Suggested change
object[] eraInfo = (object[])typeof(JapaneseCalendar).GetMethod("GetEraInfo", BindingFlags.NonPublic | BindingFlags.Static)!.Invoke(null, null)!;
Type eraInfoType = Type.GetType("System.Globalization.EraInfo, System.Private.CoreLib")!;
MethodInfo getEraInfoMethod = typeof(JapaneseCalendar).GetMethod("GetEraInfo", BindingFlags.NonPublic | BindingFlags.Static)!;
object[] eraInfo = (object[])getEraInfoMethod.Invoke(null, null)!;
Type eraInfoType = getEraInfoMethod.ReturnType.GetElementType()!;

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants