From 3b2c882376b7ffe87d05844aec034c4323fbfc3c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 24 Jul 2025 21:22:39 +0000 Subject: [PATCH 1/7] Initial plan From 467b6ac6516de93aa08698762230f8bf24c2e158 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 24 Jul 2025 22:12:11 +0000 Subject: [PATCH 2/7] Add assembly resolution downgrade tests for extension mechanisms Co-authored-by: elinor-fung <47805090+elinor-fung@users.noreply.github.com> --- .../tests/AssemblyResolutionDowngradeTest.cs | 236 ++++++++++++++++++ ...untime.Loader.Test.AssemblyVersion1.csproj | 13 + .../VersionTestClass.cs | 15 ++ ...untime.Loader.Test.AssemblyVersion3.csproj | 13 + .../VersionTestClass.cs | 15 ++ .../tests/System.Runtime.Loader.Tests.csproj | 3 + 6 files changed, 295 insertions(+) create mode 100644 src/libraries/System.Runtime.Loader/tests/AssemblyResolutionDowngradeTest.cs create mode 100644 src/libraries/System.Runtime.Loader/tests/System.Runtime.Loader.Test.AssemblyVersion1/System.Runtime.Loader.Test.AssemblyVersion1.csproj create mode 100644 src/libraries/System.Runtime.Loader/tests/System.Runtime.Loader.Test.AssemblyVersion1/VersionTestClass.cs create mode 100644 src/libraries/System.Runtime.Loader/tests/System.Runtime.Loader.Test.AssemblyVersion3/System.Runtime.Loader.Test.AssemblyVersion3.csproj create mode 100644 src/libraries/System.Runtime.Loader/tests/System.Runtime.Loader.Test.AssemblyVersion3/VersionTestClass.cs diff --git a/src/libraries/System.Runtime.Loader/tests/AssemblyResolutionDowngradeTest.cs b/src/libraries/System.Runtime.Loader/tests/AssemblyResolutionDowngradeTest.cs new file mode 100644 index 00000000000000..c5a5b3f2eb85fc --- /dev/null +++ b/src/libraries/System.Runtime.Loader/tests/AssemblyResolutionDowngradeTest.cs @@ -0,0 +1,236 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.IO; +using System.Reflection; +using Microsoft.DotNet.RemoteExecutor; +using Xunit; + +namespace System.Runtime.Loader.Tests +{ + public class AssemblyResolutionDowngradeTest : FileCleanupTestBase + { + private const string TestAssemblyName = "System.Runtime.Loader.Test.VersionDowngrade"; + + /// + /// Test that AppDomain.AssemblyResolve can resolve a higher version request with a lower version assembly. + /// This tests the scenario where code requests assembly version 3.0.0 but the resolver provides 1.0.0. + /// + [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] + public void AppDomainAssemblyResolve_CanDowngradeVersion() + { + RemoteExecutor.Invoke(() => { + string assemblyV1Path = GetTestAssemblyPath("System.Runtime.Loader.Test.AssemblyVersion1"); + string assemblyV3Path = GetTestAssemblyPath("System.Runtime.Loader.Test.AssemblyVersion3"); + + bool resolverCalled = false; + + ResolveEventHandler handler = (sender, args) => + { + Assert.Same(AppDomain.CurrentDomain, sender); + Assert.NotNull(args); + Assert.NotNull(args.Name); + + var requestedName = new AssemblyName(args.Name); + if (requestedName.Name == TestAssemblyName) + { + resolverCalled = true; + // Request is for version 3.0, but we return version 1.0 (downgrade) + Assert.Equal(new Version(3, 0, 0, 0), requestedName.Version); + return Assembly.LoadFile(assemblyV1Path); + } + return null; + }; + + AppDomain.CurrentDomain.AssemblyResolve += handler; + + try + { + // Request version 3.0.0 but expect to get 1.0.0 via downgrade + var requestedAssemblyName = new AssemblyName($"{TestAssemblyName}, Version=3.0.0.0"); + Assembly resolvedAssembly = Assembly.Load(requestedAssemblyName); + + Assert.NotNull(resolvedAssembly); + Assert.True(resolverCalled, "Assembly resolver should have been called"); + + // Verify we got the 1.0.0 assembly (downgrade successful) + Assert.Equal(new Version(1, 0, 0, 0), resolvedAssembly.GetName().Version); + + // Verify the assembly works as expected + Type testType = resolvedAssembly.GetType("System.Runtime.Loader.Tests.VersionTestClass"); + Assert.NotNull(testType); + + string version = (string)testType.GetMethod("GetVersion").Invoke(null, null); + Assert.Equal("1.0.0", version); + } + finally + { + AppDomain.CurrentDomain.AssemblyResolve -= handler; + } + }).Dispose(); + } + + /// + /// Test that AssemblyLoadContext.Resolving event can resolve a higher version request with a lower version assembly. + /// + [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] + public void AssemblyLoadContextResolving_CanDowngradeVersion() + { + RemoteExecutor.Invoke(() => { + string assemblyV1Path = GetTestAssemblyPath("System.Runtime.Loader.Test.AssemblyVersion1"); + string assemblyV3Path = GetTestAssemblyPath("System.Runtime.Loader.Test.AssemblyVersion3"); + + bool resolverCalled = false; + + Func handler = (context, name) => + { + if (name.Name == TestAssemblyName) + { + resolverCalled = true; + // Request is for version 3.0, but we return version 1.0 (downgrade) + Assert.Equal(new Version(3, 0, 0, 0), name.Version); + return context.LoadFromAssemblyPath(assemblyV1Path); + } + return null; + }; + + AssemblyLoadContext.Default.Resolving += handler; + + try + { + // Request version 3.0.0 but expect to get 1.0.0 via downgrade + var requestedAssemblyName = new AssemblyName($"{TestAssemblyName}, Version=3.0.0.0"); + Assembly resolvedAssembly = AssemblyLoadContext.Default.LoadFromAssemblyName(requestedAssemblyName); + + Assert.NotNull(resolvedAssembly); + Assert.True(resolverCalled, "Assembly resolver should have been called"); + + // Verify we got the 1.0.0 assembly (downgrade successful) + Assert.Equal(new Version(1, 0, 0, 0), resolvedAssembly.GetName().Version); + + // Verify the assembly works as expected + Type testType = resolvedAssembly.GetType("System.Runtime.Loader.Tests.VersionTestClass"); + Assert.NotNull(testType); + + string version = (string)testType.GetMethod("GetVersion").Invoke(null, null); + Assert.Equal("1.0.0", version); + } + finally + { + AssemblyLoadContext.Default.Resolving -= handler; + } + }).Dispose(); + } + + /// + /// Test that a custom AssemblyLoadContext.Load override can resolve a higher version request with a lower version assembly. + /// + [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] + public void CustomAssemblyLoadContextLoad_CanDowngradeVersion() + { + RemoteExecutor.Invoke(() => { + string assemblyV1Path = GetTestAssemblyPath("System.Runtime.Loader.Test.AssemblyVersion1"); + string assemblyV3Path = GetTestAssemblyPath("System.Runtime.Loader.Test.AssemblyVersion3"); + + var customContext = new DowngradeAssemblyLoadContext(assemblyV1Path); + + // Request version 3.0.0 but expect to get 1.0.0 via downgrade + var requestedAssemblyName = new AssemblyName($"{TestAssemblyName}, Version=3.0.0.0"); + Assembly resolvedAssembly = customContext.LoadFromAssemblyName(requestedAssemblyName); + + Assert.NotNull(resolvedAssembly); + Assert.True(customContext.LoadCalled, "Custom Load method should have been called"); + + // Verify we got the 1.0.0 assembly (downgrade successful) + Assert.Equal(new Version(1, 0, 0, 0), resolvedAssembly.GetName().Version); + + // Verify the assembly works as expected + Type testType = resolvedAssembly.GetType("System.Runtime.Loader.Tests.VersionTestClass"); + Assert.NotNull(testType); + + string version = (string)testType.GetMethod("GetVersion").Invoke(null, null); + Assert.Equal("1.0.0", version); + + // Verify that the correct ALC loaded the assembly + Assert.Equal(customContext, AssemblyLoadContext.GetLoadContext(resolvedAssembly)); + }).Dispose(); + } + + /// + /// Test that normal runtime resolution (without extension mechanisms) will NOT allow downgrades. + /// This test verifies the baseline behavior that downgrades only work via extension mechanisms. + /// + [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] + public void NormalResolution_CannotDowngradeVersion() + { + RemoteExecutor.Invoke(() => { + string assemblyV1Path = GetTestAssemblyPath("System.Runtime.Loader.Test.AssemblyVersion1"); + + // Try to load version 3.0.0 directly without any resolvers - this should fail + // since the runtime cannot find an assembly with that exact version + var requestedAssemblyName = new AssemblyName($"{TestAssemblyName}, Version=3.0.0.0"); + + Assert.Throws(() => + AssemblyLoadContext.Default.LoadFromAssemblyName(requestedAssemblyName)); + }).Dispose(); + } + + private static string GetTestAssemblyPath(string assemblyProject) + { + // Map project names to actual embedded resource names + string resourceName = assemblyProject switch + { + "System.Runtime.Loader.Test.AssemblyVersion1" => "System.Runtime.Loader.Tests.System.Runtime.Loader.Test.AssemblyVersion1.dll", + "System.Runtime.Loader.Test.AssemblyVersion3" => "System.Runtime.Loader.Tests.System.Runtime.Loader.Test.AssemblyVersion3.dll", + _ => throw new ArgumentException($"Unknown test assembly project: {assemblyProject}") + }; + + // Extract the embedded assembly to a temporary file + string tempPath = Path.Combine(Path.GetTempPath(), $"{assemblyProject}_{Guid.NewGuid()}.dll"); + + using (Stream resourceStream = typeof(AssemblyResolutionDowngradeTest).Assembly.GetManifestResourceStream(resourceName)) + { + if (resourceStream is null) + { + throw new FileNotFoundException($"Could not find embedded resource: {resourceName}"); + } + + using (FileStream fileStream = File.Create(tempPath)) + { + resourceStream.CopyTo(fileStream); + } + } + + return tempPath; + } + } + + /// + /// Custom AssemblyLoadContext that can downgrade version requests. + /// + internal class DowngradeAssemblyLoadContext : AssemblyLoadContext + { + private readonly string _downgradePath; + + public bool LoadCalled { get; private set; } + + public DowngradeAssemblyLoadContext(string downgradePath) : base("DowngradeContext") + { + _downgradePath = downgradePath; + } + + protected override Assembly Load(AssemblyName assemblyName) + { + LoadCalled = true; + + if (assemblyName.Name == "System.Runtime.Loader.Test.VersionDowngrade") + { + // Request is for version 3.0, but we return version 1.0 (downgrade) + Assert.Equal(new Version(3, 0, 0, 0), assemblyName.Version); + return LoadFromAssemblyPath(_downgradePath); + } + + return null; + } + } +} \ No newline at end of file diff --git a/src/libraries/System.Runtime.Loader/tests/System.Runtime.Loader.Test.AssemblyVersion1/System.Runtime.Loader.Test.AssemblyVersion1.csproj b/src/libraries/System.Runtime.Loader/tests/System.Runtime.Loader.Test.AssemblyVersion1/System.Runtime.Loader.Test.AssemblyVersion1.csproj new file mode 100644 index 00000000000000..b50eb00e2e5a54 --- /dev/null +++ b/src/libraries/System.Runtime.Loader/tests/System.Runtime.Loader.Test.AssemblyVersion1/System.Runtime.Loader.Test.AssemblyVersion1.csproj @@ -0,0 +1,13 @@ + + + $(NetCoreAppCurrent);netstandard2.0 + 1.0.0.0 + 1.0.0.0 + 1.0.0 + System.Runtime.Loader.Test.VersionDowngrade + false + + + + + \ No newline at end of file diff --git a/src/libraries/System.Runtime.Loader/tests/System.Runtime.Loader.Test.AssemblyVersion1/VersionTestClass.cs b/src/libraries/System.Runtime.Loader/tests/System.Runtime.Loader.Test.AssemblyVersion1/VersionTestClass.cs new file mode 100644 index 00000000000000..53f5e23dc11ff3 --- /dev/null +++ b/src/libraries/System.Runtime.Loader/tests/System.Runtime.Loader.Test.AssemblyVersion1/VersionTestClass.cs @@ -0,0 +1,15 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace System.Runtime.Loader.Tests +{ + public class VersionTestClass + { + public static string GetVersion() => "1.0.0"; + + public static string GetAssemblyVersion() + { + return typeof(VersionTestClass).Assembly.GetName().Version?.ToString() ?? "Unknown"; + } + } +} \ No newline at end of file diff --git a/src/libraries/System.Runtime.Loader/tests/System.Runtime.Loader.Test.AssemblyVersion3/System.Runtime.Loader.Test.AssemblyVersion3.csproj b/src/libraries/System.Runtime.Loader/tests/System.Runtime.Loader.Test.AssemblyVersion3/System.Runtime.Loader.Test.AssemblyVersion3.csproj new file mode 100644 index 00000000000000..e47919d8c9b8a5 --- /dev/null +++ b/src/libraries/System.Runtime.Loader/tests/System.Runtime.Loader.Test.AssemblyVersion3/System.Runtime.Loader.Test.AssemblyVersion3.csproj @@ -0,0 +1,13 @@ + + + $(NetCoreAppCurrent);netstandard2.0 + 3.0.0.0 + 3.0.0.0 + 3.0.0 + System.Runtime.Loader.Test.VersionDowngrade + false + + + + + \ No newline at end of file diff --git a/src/libraries/System.Runtime.Loader/tests/System.Runtime.Loader.Test.AssemblyVersion3/VersionTestClass.cs b/src/libraries/System.Runtime.Loader/tests/System.Runtime.Loader.Test.AssemblyVersion3/VersionTestClass.cs new file mode 100644 index 00000000000000..b43845d8b11a2d --- /dev/null +++ b/src/libraries/System.Runtime.Loader/tests/System.Runtime.Loader.Test.AssemblyVersion3/VersionTestClass.cs @@ -0,0 +1,15 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace System.Runtime.Loader.Tests +{ + public class VersionTestClass + { + public static string GetVersion() => "3.0.0"; + + public static string GetAssemblyVersion() + { + return typeof(VersionTestClass).Assembly.GetName().Version?.ToString() ?? "Unknown"; + } + } +} \ No newline at end of file diff --git a/src/libraries/System.Runtime.Loader/tests/System.Runtime.Loader.Tests.csproj b/src/libraries/System.Runtime.Loader/tests/System.Runtime.Loader.Tests.csproj index 921723bdc304ed..34cf70fd758c86 100644 --- a/src/libraries/System.Runtime.Loader/tests/System.Runtime.Loader.Tests.csproj +++ b/src/libraries/System.Runtime.Loader/tests/System.Runtime.Loader.Tests.csproj @@ -30,6 +30,7 @@ + @@ -50,6 +51,8 @@ + + From 3a3d30ff3f250a9e8de6ee98f3f1891fd3723fe2 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 24 Jul 2025 22:13:18 +0000 Subject: [PATCH 3/7] Fix assembly resolution downgrade tests - all tests now passing Co-authored-by: elinor-fung <47805090+elinor-fung@users.noreply.github.com> --- .../tests/AssemblyResolutionDowngradeTest.cs | 4 ++-- .../tests/System.Runtime.Loader.Tests.csproj | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libraries/System.Runtime.Loader/tests/AssemblyResolutionDowngradeTest.cs b/src/libraries/System.Runtime.Loader/tests/AssemblyResolutionDowngradeTest.cs index c5a5b3f2eb85fc..1e3024c5436983 100644 --- a/src/libraries/System.Runtime.Loader/tests/AssemblyResolutionDowngradeTest.cs +++ b/src/libraries/System.Runtime.Loader/tests/AssemblyResolutionDowngradeTest.cs @@ -180,8 +180,8 @@ private static string GetTestAssemblyPath(string assemblyProject) // Map project names to actual embedded resource names string resourceName = assemblyProject switch { - "System.Runtime.Loader.Test.AssemblyVersion1" => "System.Runtime.Loader.Tests.System.Runtime.Loader.Test.AssemblyVersion1.dll", - "System.Runtime.Loader.Test.AssemblyVersion3" => "System.Runtime.Loader.Tests.System.Runtime.Loader.Test.AssemblyVersion3.dll", + "System.Runtime.Loader.Test.AssemblyVersion1" => "System.Runtime.Loader.Tests.AssemblyVersion1.dll", + "System.Runtime.Loader.Test.AssemblyVersion3" => "System.Runtime.Loader.Tests.AssemblyVersion3.dll", _ => throw new ArgumentException($"Unknown test assembly project: {assemblyProject}") }; diff --git a/src/libraries/System.Runtime.Loader/tests/System.Runtime.Loader.Tests.csproj b/src/libraries/System.Runtime.Loader/tests/System.Runtime.Loader.Tests.csproj index 34cf70fd758c86..74d19df24bef2e 100644 --- a/src/libraries/System.Runtime.Loader/tests/System.Runtime.Loader.Tests.csproj +++ b/src/libraries/System.Runtime.Loader/tests/System.Runtime.Loader.Tests.csproj @@ -51,8 +51,8 @@ - - + + From 79acd8097f13042d08e3084f435ede274c74648a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 25 Jul 2025 04:39:49 +0000 Subject: [PATCH 4/7] Address reviewer feedback: improve downgrade test and move class to private Co-authored-by: elinor-fung <47805090+elinor-fung@users.noreply.github.com> --- .../tests/AssemblyResolutionDowngradeTest.cs | 52 ++++++++++--------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/src/libraries/System.Runtime.Loader/tests/AssemblyResolutionDowngradeTest.cs b/src/libraries/System.Runtime.Loader/tests/AssemblyResolutionDowngradeTest.cs index 1e3024c5436983..96702300836174 100644 --- a/src/libraries/System.Runtime.Loader/tests/AssemblyResolutionDowngradeTest.cs +++ b/src/libraries/System.Runtime.Loader/tests/AssemblyResolutionDowngradeTest.cs @@ -166,8 +166,12 @@ public void NormalResolution_CannotDowngradeVersion() RemoteExecutor.Invoke(() => { string assemblyV1Path = GetTestAssemblyPath("System.Runtime.Loader.Test.AssemblyVersion1"); - // Try to load version 3.0.0 directly without any resolvers - this should fail - // since the runtime cannot find an assembly with that exact version + // First, load the version 1.0.0 assembly into the default context + Assembly loadedV1 = AssemblyLoadContext.Default.LoadFromAssemblyPath(assemblyV1Path); + Assert.Equal(new Version(1, 0, 0, 0), loadedV1.GetName().Version); + + // Now try to load version 3.0.0 - normal resolution should NOT automatically + // downgrade to the already-loaded 1.0.0 version, it should fail var requestedAssemblyName = new AssemblyName($"{TestAssemblyName}, Version=3.0.0.0"); Assert.Throws(() => @@ -203,34 +207,34 @@ private static string GetTestAssemblyPath(string assemblyProject) return tempPath; } - } - /// - /// Custom AssemblyLoadContext that can downgrade version requests. - /// - internal class DowngradeAssemblyLoadContext : AssemblyLoadContext - { - private readonly string _downgradePath; - - public bool LoadCalled { get; private set; } - - public DowngradeAssemblyLoadContext(string downgradePath) : base("DowngradeContext") - { - _downgradePath = downgradePath; - } - - protected override Assembly Load(AssemblyName assemblyName) + /// + /// Custom AssemblyLoadContext that can downgrade version requests. + /// + private class DowngradeAssemblyLoadContext : AssemblyLoadContext { - LoadCalled = true; + private readonly string _downgradePath; + + public bool LoadCalled { get; private set; } - if (assemblyName.Name == "System.Runtime.Loader.Test.VersionDowngrade") + public DowngradeAssemblyLoadContext(string downgradePath) : base("DowngradeContext") { - // Request is for version 3.0, but we return version 1.0 (downgrade) - Assert.Equal(new Version(3, 0, 0, 0), assemblyName.Version); - return LoadFromAssemblyPath(_downgradePath); + _downgradePath = downgradePath; } - return null; + protected override Assembly Load(AssemblyName assemblyName) + { + LoadCalled = true; + + if (assemblyName.Name == TestAssemblyName) + { + // Request is for version 3.0, but we return version 1.0 (downgrade) + Assert.Equal(new Version(3, 0, 0, 0), assemblyName.Version); + return LoadFromAssemblyPath(_downgradePath); + } + + return null; + } } } } \ No newline at end of file From f2ad2fea67e783754cb21b888c54d64581230786 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 25 Jul 2025 17:00:58 +0000 Subject: [PATCH 5/7] Account for Mono runtime downgrade behavior in NormalResolution test Co-authored-by: elinor-fung <47805090+elinor-fung@users.noreply.github.com> --- .../tests/AssemblyResolutionDowngradeTest.cs | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/libraries/System.Runtime.Loader/tests/AssemblyResolutionDowngradeTest.cs b/src/libraries/System.Runtime.Loader/tests/AssemblyResolutionDowngradeTest.cs index 96702300836174..7a5a8f7426bd89 100644 --- a/src/libraries/System.Runtime.Loader/tests/AssemblyResolutionDowngradeTest.cs +++ b/src/libraries/System.Runtime.Loader/tests/AssemblyResolutionDowngradeTest.cs @@ -159,6 +159,7 @@ public void CustomAssemblyLoadContextLoad_CanDowngradeVersion() /// /// Test that normal runtime resolution (without extension mechanisms) will NOT allow downgrades. /// This test verifies the baseline behavior that downgrades only work via extension mechanisms. + /// Note: On Mono, downgrades are allowed even in normal resolution, so this test behaves differently. /// [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] public void NormalResolution_CannotDowngradeVersion() @@ -170,12 +171,25 @@ public void NormalResolution_CannotDowngradeVersion() Assembly loadedV1 = AssemblyLoadContext.Default.LoadFromAssemblyPath(assemblyV1Path); Assert.Equal(new Version(1, 0, 0, 0), loadedV1.GetName().Version); - // Now try to load version 3.0.0 - normal resolution should NOT automatically - // downgrade to the already-loaded 1.0.0 version, it should fail + // Now try to load version 3.0.0 var requestedAssemblyName = new AssemblyName($"{TestAssemblyName}, Version=3.0.0.0"); - Assert.Throws(() => - AssemblyLoadContext.Default.LoadFromAssemblyName(requestedAssemblyName)); + if (PlatformDetection.IsMonoRuntime) + { + // On Mono, normal resolution allows downgrades, so this should succeed + // and return the already-loaded 1.0.0 assembly + Assembly resolvedAssembly = AssemblyLoadContext.Default.LoadFromAssemblyName(requestedAssemblyName); + Assert.NotNull(resolvedAssembly); + Assert.Equal(new Version(1, 0, 0, 0), resolvedAssembly.GetName().Version); + Assert.Same(loadedV1, resolvedAssembly); + } + else + { + // On CoreCLR, normal resolution should NOT automatically + // downgrade to the already-loaded 1.0.0 version, it should fail + Assert.Throws(() => + AssemblyLoadContext.Default.LoadFromAssemblyName(requestedAssemblyName)); + } }).Dispose(); } From cfb35e5aa9171d66caefd8f0c3b282f328dcb358 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 28 Jul 2025 19:11:05 +0000 Subject: [PATCH 6/7] Remove unused AssemblyVersion3 project and references Co-authored-by: elinor-fung <47805090+elinor-fung@users.noreply.github.com> --- .../tests/AssemblyResolutionDowngradeTest.cs | 4 ---- ...em.Runtime.Loader.Test.AssemblyVersion3.csproj | 13 ------------- .../VersionTestClass.cs | 15 --------------- .../tests/System.Runtime.Loader.Tests.csproj | 1 - 4 files changed, 33 deletions(-) delete mode 100644 src/libraries/System.Runtime.Loader/tests/System.Runtime.Loader.Test.AssemblyVersion3/System.Runtime.Loader.Test.AssemblyVersion3.csproj delete mode 100644 src/libraries/System.Runtime.Loader/tests/System.Runtime.Loader.Test.AssemblyVersion3/VersionTestClass.cs diff --git a/src/libraries/System.Runtime.Loader/tests/AssemblyResolutionDowngradeTest.cs b/src/libraries/System.Runtime.Loader/tests/AssemblyResolutionDowngradeTest.cs index 7a5a8f7426bd89..f0f7de9c208fa6 100644 --- a/src/libraries/System.Runtime.Loader/tests/AssemblyResolutionDowngradeTest.cs +++ b/src/libraries/System.Runtime.Loader/tests/AssemblyResolutionDowngradeTest.cs @@ -21,7 +21,6 @@ public void AppDomainAssemblyResolve_CanDowngradeVersion() { RemoteExecutor.Invoke(() => { string assemblyV1Path = GetTestAssemblyPath("System.Runtime.Loader.Test.AssemblyVersion1"); - string assemblyV3Path = GetTestAssemblyPath("System.Runtime.Loader.Test.AssemblyVersion3"); bool resolverCalled = false; @@ -78,7 +77,6 @@ public void AssemblyLoadContextResolving_CanDowngradeVersion() { RemoteExecutor.Invoke(() => { string assemblyV1Path = GetTestAssemblyPath("System.Runtime.Loader.Test.AssemblyVersion1"); - string assemblyV3Path = GetTestAssemblyPath("System.Runtime.Loader.Test.AssemblyVersion3"); bool resolverCalled = false; @@ -130,7 +128,6 @@ public void CustomAssemblyLoadContextLoad_CanDowngradeVersion() { RemoteExecutor.Invoke(() => { string assemblyV1Path = GetTestAssemblyPath("System.Runtime.Loader.Test.AssemblyVersion1"); - string assemblyV3Path = GetTestAssemblyPath("System.Runtime.Loader.Test.AssemblyVersion3"); var customContext = new DowngradeAssemblyLoadContext(assemblyV1Path); @@ -199,7 +196,6 @@ private static string GetTestAssemblyPath(string assemblyProject) string resourceName = assemblyProject switch { "System.Runtime.Loader.Test.AssemblyVersion1" => "System.Runtime.Loader.Tests.AssemblyVersion1.dll", - "System.Runtime.Loader.Test.AssemblyVersion3" => "System.Runtime.Loader.Tests.AssemblyVersion3.dll", _ => throw new ArgumentException($"Unknown test assembly project: {assemblyProject}") }; diff --git a/src/libraries/System.Runtime.Loader/tests/System.Runtime.Loader.Test.AssemblyVersion3/System.Runtime.Loader.Test.AssemblyVersion3.csproj b/src/libraries/System.Runtime.Loader/tests/System.Runtime.Loader.Test.AssemblyVersion3/System.Runtime.Loader.Test.AssemblyVersion3.csproj deleted file mode 100644 index e47919d8c9b8a5..00000000000000 --- a/src/libraries/System.Runtime.Loader/tests/System.Runtime.Loader.Test.AssemblyVersion3/System.Runtime.Loader.Test.AssemblyVersion3.csproj +++ /dev/null @@ -1,13 +0,0 @@ - - - $(NetCoreAppCurrent);netstandard2.0 - 3.0.0.0 - 3.0.0.0 - 3.0.0 - System.Runtime.Loader.Test.VersionDowngrade - false - - - - - \ No newline at end of file diff --git a/src/libraries/System.Runtime.Loader/tests/System.Runtime.Loader.Test.AssemblyVersion3/VersionTestClass.cs b/src/libraries/System.Runtime.Loader/tests/System.Runtime.Loader.Test.AssemblyVersion3/VersionTestClass.cs deleted file mode 100644 index b43845d8b11a2d..00000000000000 --- a/src/libraries/System.Runtime.Loader/tests/System.Runtime.Loader.Test.AssemblyVersion3/VersionTestClass.cs +++ /dev/null @@ -1,15 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -namespace System.Runtime.Loader.Tests -{ - public class VersionTestClass - { - public static string GetVersion() => "3.0.0"; - - public static string GetAssemblyVersion() - { - return typeof(VersionTestClass).Assembly.GetName().Version?.ToString() ?? "Unknown"; - } - } -} \ No newline at end of file diff --git a/src/libraries/System.Runtime.Loader/tests/System.Runtime.Loader.Tests.csproj b/src/libraries/System.Runtime.Loader/tests/System.Runtime.Loader.Tests.csproj index 74d19df24bef2e..f9f54c521f0240 100644 --- a/src/libraries/System.Runtime.Loader/tests/System.Runtime.Loader.Tests.csproj +++ b/src/libraries/System.Runtime.Loader/tests/System.Runtime.Loader.Tests.csproj @@ -52,7 +52,6 @@ - From 7f6d413f3fb85a0d62fae4988ec9655c3ac8b358 Mon Sep 17 00:00:00 2001 From: Elinor Fung Date: Tue, 5 Aug 2025 14:21:00 -0700 Subject: [PATCH 7/7] Update src/libraries/System.Runtime.Loader/tests/System.Runtime.Loader.Test.AssemblyVersion1/VersionTestClass.cs --- .../VersionTestClass.cs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/libraries/System.Runtime.Loader/tests/System.Runtime.Loader.Test.AssemblyVersion1/VersionTestClass.cs b/src/libraries/System.Runtime.Loader/tests/System.Runtime.Loader.Test.AssemblyVersion1/VersionTestClass.cs index 53f5e23dc11ff3..5e6d347447ca4d 100644 --- a/src/libraries/System.Runtime.Loader/tests/System.Runtime.Loader.Test.AssemblyVersion1/VersionTestClass.cs +++ b/src/libraries/System.Runtime.Loader/tests/System.Runtime.Loader.Test.AssemblyVersion1/VersionTestClass.cs @@ -5,11 +5,7 @@ namespace System.Runtime.Loader.Tests { public class VersionTestClass { - public static string GetVersion() => "1.0.0"; - - public static string GetAssemblyVersion() - { - return typeof(VersionTestClass).Assembly.GetName().Version?.ToString() ?? "Unknown"; - } + public static string GetVersion() + => typeof(VersionTestClass).Assembly.GetName().Version?.ToString(3) ?? "Unknown"; } } \ No newline at end of file