Skip to content

[mobile] Skip AssemblyLoadContext tests using Assembly.Location on mobile#127082

Merged
kotlarmilos merged 3 commits intomainfrom
mobile-fix-runtime-loader-tests-e99cbef9a2866fc9
Apr 20, 2026
Merged

[mobile] Skip AssemblyLoadContext tests using Assembly.Location on mobile#127082
kotlarmilos merged 3 commits intomainfrom
mobile-fix-runtime-loader-tests-e99cbef9a2866fc9

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

Fixes test failures on Android, iOS, tvOS, and MacCatalyst discovered in build #1383320.

Failure

Test: System.Runtime.Loader.Tests.AssemblyLoadContextTest
Helix job: c1e7d30b-9f1d-4f11-9117-cfe78a4df8b9
Work item: System.Runtime.Loader.Tests
Platform: android-arm64 (also affects all mobile platforms)

Failing tests

  1. InvalidCastException_DifferentALC_ShowsAssemblyInfo
  2. InvalidCastException_GenericTypeArg_DifferentALC_ShowsAssemblyInfo

Root cause

Both tests call LoadFromAssemblyPath(typeof(AssemblyLoadContextTest).Assembly.Location). On mobile platforms, Assembly.Location returns an empty string because assemblies are loaded from the APK/app bundle, not from individual files on disk.

[FAIL] System.Runtime.Loader.Tests.AssemblyLoadContextTest.InvalidCastException_DifferentALC_ShowsAssemblyInfo
System.ArgumentException : Path "" is not an absolute path. (Parameter 'assemblyPath')
   at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyPath(String assemblyPath)
   at System.Runtime.Loader.Tests.AssemblyLoadContextTest.InvalidCastException_DifferentALC_ShowsAssemblyInfo()

Fix

Add nameof(PlatformDetection.IsNotMobile) to both tests' ConditionalFact attributes to skip on mobile platforms where Assembly.Location is not available.

Testing

These tests will be skipped on Android, iOS, tvOS, and MacCatalyst in the runtime-extra-platforms pipeline. Desktop platforms will continue to run the tests.


Note

This PR was created by GitHub Copilot after analyzing mobile platform CI failures in the runtime-extra-platforms pipeline.

Contributes to #127080

Generated by Mobile Platform Failure Scanner · ● 4.9M ·

These tests fail on mobile platforms because Assembly.Location returns an empty string.
On mobile, assemblies are loaded from the APK/app bundle, not from individual files.

Fixes failures discovered in build #1383320:
- InvalidCastException_DifferentALC_ShowsAssemblyInfo
- InvalidCastException_GenericTypeArg_DifferentALC_ShowsAssemblyInfo

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@dotnet-policy-service
Copy link
Copy Markdown
Contributor

Tagging subscribers to 'os-tvos': @vitek-karas, @kotlarmilos, @steveisok, @akoeplinger
See info in area-owners.md if you want to be subscribed.

@kotlarmilos kotlarmilos marked this pull request as ready for review April 17, 2026 13:31
Copilot AI review requested due to automatic review settings April 17, 2026 13:31
@github-actions
Copy link
Copy Markdown
Contributor Author

Note

This review was generated by Copilot.

🤖 Copilot Code Review — PR #127082

Holistic Assessment

Motivation: The PR is justified. Both tests call LoadFromAssemblyPath(typeof(AssemblyLoadContextTest).Assembly.Location), and on mobile platforms Assembly.Location returns an empty string because assemblies are bundled in the APK/app bundle. Skipping them on mobile is the correct response.

Approach: The fix works functionally, but uses PlatformDetection.IsNotMobile where the established convention in this same test directory is PlatformDetection.HasAssemblyFiles — a more precise check that directly tests the actual precondition.

Summary: ⚠️ Needs Human Review. The skip is functionally correct and will resolve the mobile failures. However, it diverges from the well-established convention used by 10+ sibling tests in the same directory. A human reviewer should decide whether to accept as-is or align with the existing HasAssemblyFiles pattern.


Detailed Findings

⚠️ Consistency — IsNotMobile vs established HasAssemblyFiles convention

Flagged by all 3 review models (Claude Opus 4.6, Claude Sonnet 4.5, GPT-5.3-Codex).

The PR adds PlatformDetection.IsNotMobile to guard tests that depend on Assembly.Location being non-empty. However, the same test directory consistently uses PlatformDetection.HasAssemblyFiles for exactly this condition:

File Line(s)
AssemblyLoadContextTest.cs 111
ContextualReflection.cs 147
LoaderLinkTest.cs 16
RefEmitLoadContextTest.cs 67
SatelliteAssemblies.cs 77, 134, 190, 211

Why HasAssemblyFiles is preferable:

  1. Semantically precise: Defined as !string.IsNullOrEmpty(typeof(PlatformDetection).Assembly.Location) — it checks the exact condition these tests depend on.
  2. Future-proof: Automatically covers any future platform or configuration (e.g., single-file deployment) where Assembly.Location is empty, without needing manual updates.
  3. Less redundant: IsNotMobile excludes Browser/WASI, but IsCoreCLR already excludes those (they don't use CoreCLR). The only net-new exclusions from IsNotMobile are Android and AppleMobile running CoreCLR — which HasAssemblyFiles would also handle.

Suggested change (both test methods at lines 280 and 301):

-[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsAssemblyLoadingSupported), nameof(PlatformDetection.IsCoreCLR), nameof(PlatformDetection.IsNotMobile))]
+[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsAssemblyLoadingSupported), nameof(PlatformDetection.IsCoreCLR), nameof(PlatformDetection.HasAssemblyFiles))]

This is advisory, not merge-blocking — the current code is functionally correct.

✅ Correctness — Skip condition prevents the right failures

The change correctly prevents both tests from running on platforms where Assembly.Location returns empty string. The IsNotMobile check does exclude all the right platforms and will resolve the reported CI failures.

Generated by Code Review for issue #127082 ·

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

Skips two System.Runtime.Loader tests on mobile platforms where Assembly.Location is empty (assemblies loaded from app bundles/APKs), preventing LoadFromAssemblyPath("") failures in mobile CI.

Changes:

  • Add PlatformDetection.IsNotMobile to the ConditionalFact guards for two AssemblyLoadContextTest test cases that rely on Assembly.Location.

Comment thread src/libraries/System.Runtime.Loader/tests/AssemblyLoadContextTest.cs Outdated
Comment thread src/libraries/System.Runtime.Loader/tests/AssemblyLoadContextTest.cs Outdated
…bly.Location

Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/a80757bd-1d3b-4ee5-8794-14353d687456

Co-authored-by: kotlarmilos <11523312+kotlarmilos@users.noreply.github.com>
@kotlarmilos kotlarmilos merged commit 87c1f7a into main Apr 20, 2026
91 of 96 checks passed
@kotlarmilos kotlarmilos deleted the mobile-fix-runtime-loader-tests-e99cbef9a2866fc9 branch April 20, 2026 14:17
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