Skip to content

System.Runtime.Loader.Tests fails to build on Apple mobile platforms with IL2007 assembly resolution errors #127645

@github-actions

Description

@github-actions

Build Information

Build: 1403076 (2026-04-30T10:36:57Z)
Affected jobs:

  • maccatalyst-arm64 Release AllSubsets_CoreCLR
  • maccatalyst-x64 Release AllSubsets_CoreCLR
  • iossimulator-x64 Release AllSubsets_CoreCLR
  • iossimulator-arm64 Release (Mono and CoreCLR)
  • tvos-arm64 Release (Mono and CoreCLR variants)

Error

ILLink trimmer fails during library test build with assembly resolution errors:

error IL2007: Could not resolve assembly 'System.Runtime.Loader.Test.Assembly'.
error IL2007: Could not resolve assembly 'System.Runtime.Loader.Test.Assembly2'.
error NETSDK1144: Optimizing assemblies for size failed.

Source: src/libraries/System.Runtime.Loader/tests/ILLink.Descriptors.xml lines 5-6 reference test assemblies that are not available when the trimmer runs.

ILLink.Descriptors.xml content:

<linker>
  <assembly fullname="LoaderLinkTest.Dynamic" />
  <assembly fullname="ReferencedClassLib" />
  <assembly fullname="ReferencedClassLibNeutralIsSatellite" />
  <assembly fullname="System.Runtime.Loader.Test.Assembly" />
  <assembly fullname="System.Runtime.Loader.Test.Assembly2" />
</linker>

Analysis

Root cause: Build dependency ordering issue. The test assemblies System.Runtime.Loader.Test.Assembly and System.Runtime.Loader.Test.Assembly2 are separate projects under src/libraries/System.Runtime.Loader/tests/ that must be built before the main test project runs ILLink trimming.

On desktop and non-trimmed platforms, this works because:

  1. Either trimming is disabled, or
  2. The build dependency graph ensures test assemblies are built first

On Apple mobile platforms (iOS, tvOS, macCatalyst), the aggressive trimming configuration (used for app bundle size optimization) runs ILLink during the main test project build, but the dependency projects might not be referenced/built in the correct order for trimming purposes.

Evidence:

  • The test assembly projects exist in the source tree:
    • System.Runtime.Loader.Test.Assembly/System.Runtime.Loader.Test.Assembly.csproj
    • System.Runtime.Loader.Test.Assembly2/ (similar structure)
  • Other test assemblies referenced in the same descriptor (LoaderLinkTest.Dynamic, ReferencedClassLib) may build earlier in the dependency chain
  • The error is trimmer-specific (IL2007 from ILLink, not a compiler error)

Impact

Blocks all System.Runtime.Loader library tests from running on Apple mobile platforms:

  • 0 tests executed (build fails before test packaging)
  • Affects 6 mobile platform/architecture combinations across CoreCLR and Mono
  • Test coverage gap for AssemblyLoadContext, collectible assemblies, and metadata update APIs on mobile

Recommended action

Option 1: Fix build dependencies (preferred)

Ensure System.Runtime.Loader.Test.Assembly and System.Runtime.Loader.Test.Assembly2 are built (or at least their assembly references are available) before ILLink runs on the main test project. This may require:

  1. Adding explicit ProjectReference elements in System.Runtime.Loader.Tests.csproj (if not already present)
  2. Checking MSBuild target ordering to ensure dependency assemblies are resolved before RunILLink target
  3. Verifying the dependencies are included in the mobile-specific build graph (eng/testing/tests.ioslike.targets, etc.)

Option 2: Conditional descriptor inclusion

Exclude the problematic assembly references from the ILLink descriptor on mobile platforms:

<linker>
  <assembly fullname="LoaderLinkTest.Dynamic" />
  <assembly fullname="ReferencedClassLib" />
  <assembly fullname="ReferencedClassLibNeutralIsSatellite" />
  <!-- Only preserve test assemblies when they're actually built -->
  <assembly fullname="System.Runtime.Loader.Test.Assembly" Condition="..." />
  <assembly fullname="System.Runtime.Loader.Test.Assembly2" Condition="..." />
</linker>

However, ILLink descriptor XML does not support MSBuild conditions directly. This would require preprocessing or splitting descriptors.

Option 3: Disable these specific tests on mobile (workaround)

If the tests genuinely depend on dynamic assembly loading features unavailable on trimmed/AOT mobile platforms, exclude the affected test methods with [SkipOnPlatform] or adjust TargetFrameworks in the csproj. But first verify if that's actually the case — many AssemblyLoadContext tests should work on mobile.

Investigation steps

  1. Check project references: Does System.Runtime.Loader.Tests.csproj have <ProjectReference> for the test assembly projects? If not, add them.
  2. Check build logs: On a successful desktop build, confirm the dependency assemblies are built before the main test project's ILLink step. Compare with the failed mobile build.
  3. Check mobile-specific target files: Review eng/testing/tests.ioslike.targets and src/mono/msbuild/apple/build/AppleBuild.targets for custom dependency handling.
  4. Test locally: Build System.Runtime.Loader.Tests for iossimulator-x64 with verbose MSBuild logging to see the exact dependency resolution and trimming order.

Related issues

Generated by Mobile Platform Failure Scanner · ● 3.1M ·

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status

    No status

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions