From b63108057a3d086f248ca694e9d35ee3c457d588 Mon Sep 17 00:00:00 2001 From: Milos Kotlar Date: Fri, 17 Apr 2026 11:08:18 +0200 Subject: [PATCH 1/6] [ios-clr] Enable ResourceAssemblyLoadContext fallback for Apple mobile CoreCLR On Apple mobile platforms, test child-assemblies are deployed as loose files inside the .app bundle rather than embedded resources, so GetManifestResourceStream returns null. Fall back to loading from AppContext.BaseDirectory when the embedded resource is not present, honoring the existing LoadBy (Path or Stream) selection. Also remove the Apple-mobile exclusion of the System.Runtime.Loader test project from tests.proj. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../tests/ResourceAssemblyLoadContext.cs | 22 +++++++++++++++++++ src/libraries/tests.proj | 1 - 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/libraries/System.Runtime.Loader/tests/ResourceAssemblyLoadContext.cs b/src/libraries/System.Runtime.Loader/tests/ResourceAssemblyLoadContext.cs index 84ad66d3433455..8b95fb944e6338 100644 --- a/src/libraries/System.Runtime.Loader/tests/ResourceAssemblyLoadContext.cs +++ b/src/libraries/System.Runtime.Loader/tests/ResourceAssemblyLoadContext.cs @@ -31,6 +31,28 @@ protected override Assembly Load(AssemblyName assemblyName) if (asmStream == null) { + // On platforms where assemblies are deployed as files alongside the app + // (e.g., Apple mobile CoreCLR) rather than embedded resources, fall back + // to loading from the app directory. + string basePath = Path.Combine(AppContext.BaseDirectory, assembly); + if (File.Exists(basePath)) + { + if (LoadBy == LoadBy.Path) + { + var tempPath = Directory.CreateTempSubdirectory().FullName; + string path = Path.Combine(tempPath, assembly); + File.Copy(basePath, path); + return LoadFromAssemblyPath(path); + } + else if (LoadBy == LoadBy.Stream) + { + using (FileStream stream = File.OpenRead(basePath)) + { + return LoadFromStream(stream); + } + } + } + return null; } diff --git a/src/libraries/tests.proj b/src/libraries/tests.proj index 43615ce89c8823..2f15c798e56dc1 100644 --- a/src/libraries/tests.proj +++ b/src/libraries/tests.proj @@ -685,7 +685,6 @@ - From 679012c34f82d10b171538608668ec7343c7104e Mon Sep 17 00:00:00 2001 From: Milos Kotlar Date: Mon, 20 Apr 2026 16:02:13 +0200 Subject: [PATCH 2/6] [ios-clr] Preserve System.Runtime.Loader test assemblies from trimming On Apple mobile CoreCLR with aggressive trimming, ILLink was dropping System.Runtime.Loader.Test.Assembly(2).dll from the publish output because nothing at compile time references them (they're loaded via reflection through the custom ALC). This caused the ResourceAssemblyLoadContext file-system fallback to fail with FileNotFoundException. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../System.Runtime.Loader/tests/ILLink.Descriptors.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libraries/System.Runtime.Loader/tests/ILLink.Descriptors.xml b/src/libraries/System.Runtime.Loader/tests/ILLink.Descriptors.xml index 7fa0c9a0982542..991945c09a3ad2 100644 --- a/src/libraries/System.Runtime.Loader/tests/ILLink.Descriptors.xml +++ b/src/libraries/System.Runtime.Loader/tests/ILLink.Descriptors.xml @@ -2,4 +2,6 @@ + + From 7b373b3be67be39bfdd21e26cf76f4df43cf90d1 Mon Sep 17 00:00:00 2001 From: Milos Kotlar Date: Tue, 21 Apr 2026 10:25:59 +0200 Subject: [PATCH 3/6] Add System.Runtime.Loader.Noop.Assembly to linker descriptors --- src/libraries/System.Runtime.Loader/tests/ILLink.Descriptors.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libraries/System.Runtime.Loader/tests/ILLink.Descriptors.xml b/src/libraries/System.Runtime.Loader/tests/ILLink.Descriptors.xml index 991945c09a3ad2..72703ba7d05cbe 100644 --- a/src/libraries/System.Runtime.Loader/tests/ILLink.Descriptors.xml +++ b/src/libraries/System.Runtime.Loader/tests/ILLink.Descriptors.xml @@ -4,4 +4,5 @@ + From 2a5cd8669b6d5ae248adb68a36b5f5e3e22487a1 Mon Sep 17 00:00:00 2001 From: Milos Kotlar Date: Tue, 21 Apr 2026 15:06:31 +0200 Subject: [PATCH 4/6] Fix ILLink failures for System.Runtime.Loader tests on Apple mobile - Remove System.Runtime.Loader.Noop.Assembly from the main Tests.csproj ILLink descriptor; it isn't referenced by that project (only by the DefaultContext and RefEmitLoadContext test projects), causing IL2007. - Preserve Noop.Assembly from trimming in DefaultContext.Tests and RefEmitLoadContext.Tests. On Apple mobile with EnableAggressiveTrimming, ConfigureTrimming marks every ResolvedFileToPublish with TrimMode=link, including ContentWithTargetPath copies. Since Noop.Assembly is loaded purely via reflection, TestClass was stripped and GetType returned null. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- ...ystem.Runtime.Loader.DefaultContext.Tests.csproj | 13 +++++++++++++ .../tests/ILLink.Descriptors.xml | 1 - ...m.Runtime.Loader.RefEmitLoadContext.Tests.csproj | 12 ++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/libraries/System.Runtime.Loader/tests/DefaultContext/System.Runtime.Loader.DefaultContext.Tests.csproj b/src/libraries/System.Runtime.Loader/tests/DefaultContext/System.Runtime.Loader.DefaultContext.Tests.csproj index 2633ac0c4836c7..fd9de6b11bd45c 100644 --- a/src/libraries/System.Runtime.Loader/tests/DefaultContext/System.Runtime.Loader.DefaultContext.Tests.csproj +++ b/src/libraries/System.Runtime.Loader/tests/DefaultContext/System.Runtime.Loader.DefaultContext.Tests.csproj @@ -13,4 +13,17 @@ CopyToOutputDirectory="PreserveNewest" TargetPath="System.Runtime.Loader.Noop.Assembly_test.dll" /> + + + + + + + diff --git a/src/libraries/System.Runtime.Loader/tests/ILLink.Descriptors.xml b/src/libraries/System.Runtime.Loader/tests/ILLink.Descriptors.xml index 72703ba7d05cbe..991945c09a3ad2 100644 --- a/src/libraries/System.Runtime.Loader/tests/ILLink.Descriptors.xml +++ b/src/libraries/System.Runtime.Loader/tests/ILLink.Descriptors.xml @@ -4,5 +4,4 @@ - diff --git a/src/libraries/System.Runtime.Loader/tests/RefEmitLoadContext/System.Runtime.Loader.RefEmitLoadContext.Tests.csproj b/src/libraries/System.Runtime.Loader/tests/RefEmitLoadContext/System.Runtime.Loader.RefEmitLoadContext.Tests.csproj index f8242a8e212f38..c1768022412938 100644 --- a/src/libraries/System.Runtime.Loader/tests/RefEmitLoadContext/System.Runtime.Loader.RefEmitLoadContext.Tests.csproj +++ b/src/libraries/System.Runtime.Loader/tests/RefEmitLoadContext/System.Runtime.Loader.RefEmitLoadContext.Tests.csproj @@ -12,4 +12,16 @@ OutputItemType="content" CopyToOutputDirectory="PreserveNewest" /> + + + + + + + \ No newline at end of file From 41e83856c833bc1d8bdb66ac60ab213d20a578da Mon Sep 17 00:00:00 2001 From: Milos Kotlar Date: Mon, 27 Apr 2026 13:31:54 +0200 Subject: [PATCH 5/6] Refactor PreserveNoopAssemblyFromTrimming target for clarity in project files Co-authored-by: Copilot --- ...System.Runtime.Loader.DefaultContext.Tests.csproj | 11 ++--------- ...em.Runtime.Loader.RefEmitLoadContext.Tests.csproj | 12 +++--------- 2 files changed, 5 insertions(+), 18 deletions(-) diff --git a/src/libraries/System.Runtime.Loader/tests/DefaultContext/System.Runtime.Loader.DefaultContext.Tests.csproj b/src/libraries/System.Runtime.Loader/tests/DefaultContext/System.Runtime.Loader.DefaultContext.Tests.csproj index 030ebfa383c053..3b55c05d9f9e3b 100644 --- a/src/libraries/System.Runtime.Loader/tests/DefaultContext/System.Runtime.Loader.DefaultContext.Tests.csproj +++ b/src/libraries/System.Runtime.Loader/tests/DefaultContext/System.Runtime.Loader.DefaultContext.Tests.csproj @@ -16,16 +16,9 @@ TargetPath="System.Runtime.Loader.Noop.Assembly_test.dll" /> - - + - + diff --git a/src/libraries/System.Runtime.Loader/tests/RefEmitLoadContext/System.Runtime.Loader.RefEmitLoadContext.Tests.csproj b/src/libraries/System.Runtime.Loader/tests/RefEmitLoadContext/System.Runtime.Loader.RefEmitLoadContext.Tests.csproj index 76d57649768d73..f203c97e099cf6 100644 --- a/src/libraries/System.Runtime.Loader/tests/RefEmitLoadContext/System.Runtime.Loader.RefEmitLoadContext.Tests.csproj +++ b/src/libraries/System.Runtime.Loader/tests/RefEmitLoadContext/System.Runtime.Loader.RefEmitLoadContext.Tests.csproj @@ -15,15 +15,9 @@ CopyToOutputDirectory="PreserveNewest" /> - - + - + - \ No newline at end of file + From bde0e05a8e97f2ba16b2254242f3492e858feee9 Mon Sep 17 00:00:00 2001 From: Milos Kotlar Date: Tue, 28 Apr 2026 11:14:35 +0200 Subject: [PATCH 6/6] Add ActiveIssue attribute for LoadInDefaultContext test on Apple Mobile --- .../tests/DefaultContext/DefaultLoadContextTest.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libraries/System.Runtime.Loader/tests/DefaultContext/DefaultLoadContextTest.cs b/src/libraries/System.Runtime.Loader/tests/DefaultContext/DefaultLoadContextTest.cs index ab0814f4e1e7be..4d506e46437f65 100644 --- a/src/libraries/System.Runtime.Loader/tests/DefaultContext/DefaultLoadContextTest.cs +++ b/src/libraries/System.Runtime.Loader/tests/DefaultContext/DefaultLoadContextTest.cs @@ -86,6 +86,7 @@ private Assembly ResolveNullAssembly(AssemblyLoadContext sender, AssemblyName as // Does not apply to Mono AOT scenarios as it is expected the name of the .aotdata file matches // the true name of the assembly and not the physical file name. [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotMonoAOT), nameof(PlatformDetection.HasAssemblyFiles))] + [ActiveIssue("https://github.com/dotnet/runtime/issues/124344", typeof(PlatformDetection), nameof(PlatformDetection.IsAppleMobile), nameof(PlatformDetection.IsCoreCLR))] public void LoadInDefaultContext() { // This will attempt to load an assembly, by path, in the Default Load context via the Resolving event