diff --git a/src/libraries/System.Runtime/tests/System.Runtime.Tests/TrimmingTests/InvariantGlobalizationTrue.cs b/src/libraries/System.Runtime/tests/System.Runtime.Tests/TrimmingTests/InvariantGlobalizationTrue.cs index fe878e3a7459d8..27ab1b136b5a4f 100644 --- a/src/libraries/System.Runtime/tests/System.Runtime.Tests/TrimmingTests/InvariantGlobalizationTrue.cs +++ b/src/libraries/System.Runtime/tests/System.Runtime.Tests/TrimmingTests/InvariantGlobalizationTrue.cs @@ -4,6 +4,7 @@ using System; using System.Globalization; using System.Reflection; +using System.Runtime.CompilerServices; /// /// Ensures setting InvariantGlobalization = true still works in a trimmed app. @@ -27,6 +28,18 @@ static int Main(string[] args) { return -3; } + + // The rest of this code depends on a property of IL level trimming that keeps reflection + // metadata for anything that is statically reachable. It's not applicable if we're not doing that + // kind of trimming. Approximate what kind of trimming are we doing. + if (GetMethodSecretly(typeof(Program), nameof(GetCoreLibType)) == null) + { + // Sanity check: we only expect this for native AOT; IsDynamicCodeSupported approximates that. + if (RuntimeFeature.IsDynamicCodeSupported) + throw new Exception(); + + return 100; + } // Ensure the internal GlobalizationMode class is trimmed correctly. Type globalizationMode = GetCoreLibType("System.Globalization.GlobalizationMode"); @@ -65,4 +78,8 @@ static int Main(string[] args) // The intention of this method is to ensure the trimmer doesn't preserve the Type. private static Type GetCoreLibType(string name) => typeof(object).Assembly.GetType(name, throwOnError: false); + + // The intention is to look for a method on a type in a way that trimming cannot detect. + private static MethodBase GetMethodSecretly(Type type, string name) => + type.GetMethod(name, BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); } diff --git a/src/libraries/System.Runtime/tests/System.Runtime.Tests/TrimmingTests/System.Runtime.TrimmingTests.proj b/src/libraries/System.Runtime/tests/System.Runtime.Tests/TrimmingTests/System.Runtime.TrimmingTests.proj index c9c42b2c20234e..6cfdea28f5e0bd 100644 --- a/src/libraries/System.Runtime/tests/System.Runtime.Tests/TrimmingTests/System.Runtime.TrimmingTests.proj +++ b/src/libraries/System.Runtime/tests/System.Runtime.Tests/TrimmingTests/System.Runtime.TrimmingTests.proj @@ -43,6 +43,8 @@ and tested with this test. Issue https://github.com/dotnet/runtime/issues/48849 is tracking investigation on why this test is failing if not skipped. --> browser-wasm + + true + true NullabilityInfoContextSupport @@ -62,6 +66,8 @@ System.Threading.ThreadPool.UseWindowsThreadPool + + true System.Threading.ThreadPool.UseWindowsThreadPool diff --git a/src/libraries/tests.proj b/src/libraries/tests.proj index 9b0f74e1c0b1d6..1000904707dfa7 100644 --- a/src/libraries/tests.proj +++ b/src/libraries/tests.proj @@ -650,7 +650,6 @@ -