Skip to content

Fix TypeMapApp R2R test failure: re-process assembly targets in fallback mode#126075

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/fix-interop-typemapapp-tests
Draft

Fix TypeMapApp R2R test failure: re-process assembly targets in fallback mode#126075
Copilot wants to merge 2 commits intomainfrom
copilot/fix-interop-typemapapp-tests

Conversation

Copy link
Contributor

Copilot AI commented Mar 25, 2026

Description

In R2R mode, TypeMap.Validate_MissingAssemblyTarget silently passes instead of throwing FileNotFoundException when an assembly referenced by [TypeMapAssemblyTarget] doesn't exist.

Root cause: CrossGen2, when it fails to resolve a target assembly, still emits a TypeMapAssemblyTargets R2R entry for that group type with count=0 (because _targetModules is empty after the failed resolution). At runtime, HasTypeMapAssemblyTargets finds this count=0 entry and returns true, setting hasPrecachedTargets = true. The original code only re-processes assembly-target attributes when !hasPrecachedTargets, so the fallback that would call spec.LoadAssembly("DoesNotExist") and throw is never reached.

Changes

  • assemblynative.cpp — Remove the if (!hasPrecachedTargets) guard and unconditionally call ProcessTypeMapAttribute for assembly-target attributes whenever any precached map is missing/invalid (i.e., the outer fallback block is entered). AssemblyTargetProcessor deduplicates so re-processing is safe. This also handles the "mixed case" where some targets resolved but the external/proxy map failed.

  • TypeMapAssemblyTargetsNode.cs — Skip emitting TypeMapAssemblyTargets entries for groups where TargetModules.Count == 0. With no entry emitted, HasTypeMapAssemblyTargets returns falsehasPrecachedTargets = false → the runtime falls back correctly. Both GetData and ComputeNonRelocationBasedDependencies are updated consistently to skip these entries.

The two fixes are complementary: the CrossGen2 fix prevents future images from containing misleading count=0 entries; the runtime fix ensures robustness against any such entries that already exist.

Original prompt

This section details on the original issue you should resolve

<issue_title>Test failure: Interop/TypeMap/TypeMapApp/TypeMapApp.cmd</issue_title>
<issue_description>Failed in: runtime-coreclr r2r-extra 20260321.1

Failed tests:

R2R-CG2 linux arm Checked jitstress1 @ (Debian.13.Arm32.Open)AzureLinux.3.Arm64.Open@mcr.microsoft.com/dotnet-buildtools/prereqs:debian-13-helix-arm32v7
- Interop/TypeMap/TypeMapApp/TypeMapApp.cmd
R2R-CG2 linux arm Checked jitstressregs2 @ (Debian.13.Arm32.Open)AzureLinux.3.Arm64.Open@mcr.microsoft.com/dotnet-buildtools/prereqs:debian-13-helix-arm32v7
- Interop/TypeMap/TypeMapApp/TypeMapApp.cmd
R2R-CG2 linux arm Checked gcstress0xc @ (Debian.13.Arm32.Open)AzureLinux.3.Arm64.Open@mcr.microsoft.com/dotnet-buildtools/prereqs:debian-13-helix-arm32v7
- Interop/TypeMap/TypeMapApp/TypeMapApp.cmd
R2R-CG2 linux arm Checked jitminopts @ (Debian.13.Arm32.Open)AzureLinux.3.Arm64.Open@mcr.microsoft.com/dotnet-buildtools/prereqs:debian-13-helix-arm32v7
- Interop/TypeMap/TypeMapApp/TypeMapApp.cmd
R2R-CG2 linux arm Checked jitstressregs0x80 @ (Debian.13.Arm32.Open)AzureLinux.3.Arm64.Open@mcr.microsoft.com/dotnet-buildtools/prereqs:debian-13-helix-arm32v7
- Interop/TypeMap/TypeMapApp/TypeMapApp.cmd
R2R-CG2 linux arm Checked jitstressregs8 @ (Debian.13.Arm32.Open)AzureLinux.3.Arm64.Open@mcr.microsoft.com/dotnet-buildtools/prereqs:debian-13-helix-arm32v7
- Interop/TypeMap/TypeMapApp/TypeMapApp.cmd
R2R-CG2 linux arm Checked jitstressregs0x10 @ (Debian.13.Arm32.Open)AzureLinux.3.Arm64.Open@mcr.microsoft.com/dotnet-buildtools/prereqs:debian-13-helix-arm32v7
- Interop/TypeMap/TypeMapApp/TypeMapApp.cmd
R2R-CG2 linux arm Checked jitstressregs3 @ (Debian.13.Arm32.Open)AzureLinux.3.Arm64.Open@mcr.microsoft.com/dotnet-buildtools/prereqs:debian-13-helix-arm32v7
- Interop/TypeMap/TypeMapApp/TypeMapApp.cmd
R2R-CG2 linux arm Checked jitstress1_tiered @ (Debian.13.Arm32.Open)AzureLinux.3.Arm64.Open@mcr.microsoft.com/dotnet-buildtools/prereqs:debian-13-helix-arm32v7
- Interop/TypeMap/TypeMapApp/TypeMapApp.cmd
R2R-CG2 linux arm Checked jitstressregs4 @ (Debian.13.Arm32.Open)AzureLinux.3.Arm64.Open@mcr.microsoft.com/dotnet-buildtools/prereqs:debian-13-helix-arm32v7
- Interop/TypeMap/TypeMapApp/TypeMapApp.cmd
R2R-CG2 linux arm Checked jitstressregs0x2000 @ (Debian.13.Arm32.Open)AzureLinux.3.Arm64.Open@mcr.microsoft.com/dotnet-buildtools/prereqs:debian-13-helix-arm32v7
- Interop/TypeMap/TypeMapApp/TypeMapApp.cmd
R2R-CG2 linux arm Checked forcerelocs @ (Debian.13.Arm32.Open)AzureLinux.3.Arm64.Open@mcr.microsoft.com/dotnet-buildtools/prereqs:debian-13-helix-arm32v7
- Interop/TypeMap/TypeMapApp/TypeMapApp.cmd
R2R-CG2 linux arm Checked jitstressregs0x1000 @ (Debian.13.Arm32.Open)AzureLinux.3.Arm64.Open@mcr.microsoft.com/dotnet-buildtools/prereqs:debian-13-helix-arm32v7
- Interop/TypeMap/TypeMapApp/TypeMapApp.cmd
R2R-CG2 linux arm Checked jitstressregs1 @ (Debian.13.Arm32.Open)AzureLinux.3.Arm64.Open@mcr.microsoft.com/dotnet-buildtools/prereqs:debian-13-helix-arm32v7
- Interop/TypeMap/TypeMapApp/TypeMapApp.cmd
R2R-CG2 linux arm Checked jitstress2_tiered @ (Debian.13.Arm32.Open)AzureLinux.3.Arm64.Open@mcr.microsoft.com/dotnet-buildtools/prereqs:debian-13-helix-arm32v7
- Interop/TypeMap/TypeMapApp/TypeMapApp.cmd
R2R-CG2 linux arm Checked jitstress2 @ (Debian.13.Arm32.Open)AzureLinux.3.Arm64.Open@mcr.microsoft.com/dotnet-buildtools/prereqs:debian-13-helix-arm32v7
- Interop/TypeMap/TypeMapApp/TypeMapApp.cmd
R2R-CG2 linux arm64 Checked jitstressregs0x2000 @ AzureLinux.3.Arm64.Open
- Interop/TypeMap/TypeMapApp/TypeMapApp.cmd
R2R-CG2 linux arm64 Checked jitstressregs3 @ AzureLinux.3.Arm64.Open
- Interop/TypeMap/TypeMapApp/TypeMapApp.cmd
R2R-CG2 linux arm64 Checked forcerelocs @ AzureLinux.3.Arm64.Open
- Interop/TypeMap/TypeMapApp/TypeMapApp.cmd
R2R-CG2 linux arm64 Checked jitminopts @ AzureLinux.3.Arm64.Open
- Interop/TypeMap/TypeMapApp/TypeMapApp.cmd
R2R-CG2 linux arm64 Checked jitstressregs2 @ AzureLinux.3.Arm64.Open
- Interop/TypeMap/TypeMapApp/TypeMapApp.cmd
R2R-CG2 linux arm64 Checked jitstress1_tiered @ AzureLinux.3.Arm64.Open
- Interop/TypeMap/TypeMapApp/TypeMapApp.cmd
R2R-CG2 linux arm64 Checked jitstressregs4 @ AzureLinux.3.Arm64.Open
- Interop/TypeMap/TypeMapApp/TypeMapApp.cmd
R2R-CG2 linux arm64 Checked jitstress2_tiered @ AzureLinux.3.Arm64.Open
- Interop/TypeMap/TypeMapApp/TypeMapApp.cmd
R2R-CG2 linux arm64 Checked jitstressregs0x10 @ AzureLinux.3.Arm64.Open
- Interop/TypeMap/TypeMapApp/TypeMapApp.cmd
R2R-CG2 linux arm64 Checked jitstressregs0x1000 @ AzureLinux.3.Arm64.Open
- Interop/TypeMap/TypeMapApp/TypeMapApp.cmd
R2R-CG2 linux arm64 Checked jitstressregs8 @ AzureLinux.3.Arm64.Open
- Interop/TypeMap/TypeMapApp/TypeMapApp.cmd
R2R-CG2 linux arm64 Checked gcstress0xc @ AzureLinux.3.Arm64.Open
- Interop/TypeMap/TypeMapApp/TypeMapApp.cmd
R2R-CG2 linux arm64 Checked jitstress2 @ AzureLinux.3.Ar...

</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

- Fixes dotnet/runtime#125941

<!-- START COPILOT CODING AGENT TIPS -->
---

💬 Send tasks to Copilot coding agent from [Slack](https://gh.io/cca-slack-docs) and [Teams](https://gh.io/cca-teams-docs) to turn conversations into code. Copilot posts an update in your thread when it's finished.

…ack mode and skip count=0 entries in CrossGen2

When CrossGen2 encounters an unresolvable TypeMapAssemblyTarget (e.g., the named assembly
doesn't exist), it sets exception stubs for the external/proxy type maps but still emits a
TypeMapAssemblyTargets entry with count=0.  At runtime, HasTypeMapAssemblyTargets returns
true (count=0), so hasPrecachedTargets=true, and the original code skips re-processing the
assembly-target attributes.  That prevents "DoesNotExist" from ever being loaded, silently
swallowing the expected FileNotFoundException.

Fix 1 (runtime – assemblynative.cpp): Unconditionally re-process assembly-target attributes
whenever we are in fallback mode (any precached map is missing or invalid), instead of only
when hasPrecachedTargets is false.  AssemblyTargetProcessor deduplicates, so re-processing
is safe.

Fix 2 (CrossGen2 – TypeMapAssemblyTargetsNode.cs): Skip emitting assembly-target entries for
groups with no resolved targets (TargetModules.Count==0).  With no entry emitted,
HasTypeMapAssemblyTargets returns false → hasPrecachedTargets=false → the runtime falls back
correctly.  Also skip the corresponding dependency imports in
ComputeNonRelocationBasedDependencies.

Co-authored-by: mangod9 <61718172+mangod9@users.noreply.github.com>
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/5b28e9e4-36b7-4540-bf60-ae1dad172f85
Copilot AI changed the title [WIP] Fix test failure for Interop/TypeMap/TypeMapApp Fix TypeMapApp R2R test failure: re-process assembly targets in fallback mode Mar 25, 2026
Copilot AI requested a review from mangod9 March 25, 2026 07:21
@dotnet-policy-service
Copy link
Contributor

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

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.

2 participants