diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Reflection/Extensions/NonPortable/CustomAttributeInheritanceRules.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Reflection/Extensions/NonPortable/CustomAttributeInheritanceRules.cs index 2f414c13b7f3bc..4c8a28d7a65ae6 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Reflection/Extensions/NonPortable/CustomAttributeInheritanceRules.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Reflection/Extensions/NonPortable/CustomAttributeInheritanceRules.cs @@ -233,7 +233,16 @@ public sealed override ParameterInfo GetParent(ParameterInfo e) MethodInfo? methodParent = new MethodCustomAttributeSearcher().GetParent(method); if (methodParent == null) return null; - return methodParent.GetParametersNoCopy()[e.Position]; + + if (e.Position >= 0) + { + return methodParent.GetParametersNoCopy()[e.Position]; + } + else + { + Debug.Assert(e.Position == -1); + return methodParent.ReturnParameter; + } } public static readonly ParameterCustomAttributeSearcher Default = new ParameterCustomAttributeSearcher(); diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/TypeInfos/RuntimeTypeInfo.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/TypeInfos/RuntimeTypeInfo.cs index 9815e51a2a9446..870740aaa4c2f3 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/TypeInfos/RuntimeTypeInfo.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/TypeInfos/RuntimeTypeInfo.cs @@ -187,38 +187,38 @@ public sealed override MemberInfo[] GetDefaultMembers() return defaultMemberName != null ? GetMember(defaultMemberName) : Array.Empty(); } - public sealed override InterfaceMapping GetInterfaceMap([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.NonPublicMethods)] Type interfaceType) + public sealed override InterfaceMapping GetInterfaceMap([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.NonPublicMethods)] Type ifaceType) { // restrictions and known limitations compared to CoreCLR: // - only interface.GetMethods() reflection visible interface methods are returned // - all visible members of the interface must be reflection invokeable - // - this type and interfaceType must not be an open generic type + // - this type and ifaceType must not be an open generic type // - if this type and the method implementing the interface method are abstract, an exception is thrown if (IsGenericParameter) throw new InvalidOperationException(SR.Arg_GenericParameter); - if (interfaceType is null) - throw new ArgumentNullException(nameof(interfaceType)); + if (ifaceType is null) + throw new ArgumentNullException(nameof(ifaceType)); - if (!(interfaceType is RuntimeTypeInfo)) - throw new ArgumentException(SR.Argument_MustBeRuntimeType, nameof(interfaceType)); + if (!(ifaceType is RuntimeTypeInfo)) + throw new ArgumentException(SR.Argument_MustBeRuntimeType, nameof(ifaceType)); - RuntimeTypeHandle interfaceTypeHandle = interfaceType.TypeHandle; + RuntimeTypeHandle interfaceTypeHandle = ifaceType.TypeHandle; ReflectionCoreExecution.ExecutionEnvironment.VerifyInterfaceIsImplemented(TypeHandle, interfaceTypeHandle); - Debug.Assert(interfaceType.IsInterface); + Debug.Assert(ifaceType.IsInterface); Debug.Assert(!IsInterface); // SZArrays implement the methods on IList`1, IEnumerable`1, and ICollection`1 with // runtime magic. We don't have accurate interface maps for them. - if (IsSZArray && interfaceType.IsGenericType) + if (IsSZArray && ifaceType.IsGenericType) throw new ArgumentException(SR.Argument_ArrayGetInterfaceMap); - ReflectionCoreExecution.ExecutionEnvironment.GetInterfaceMap(this, interfaceType, out MethodInfo[] interfaceMethods, out MethodInfo[] targetMethods); + ReflectionCoreExecution.ExecutionEnvironment.GetInterfaceMap(this, ifaceType, out MethodInfo[] interfaceMethods, out MethodInfo[] targetMethods); InterfaceMapping im; - im.InterfaceType = interfaceType; + im.InterfaceType = ifaceType; im.TargetType = this; im.InterfaceMethods = interfaceMethods; im.TargetMethods = targetMethods; diff --git a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/ValueTypeGetFieldHelperMethodOverride.cs b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/ValueTypeGetFieldHelperMethodOverride.cs index a5cfa2db42e5ec..76c9184d4e6372 100644 --- a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/ValueTypeGetFieldHelperMethodOverride.cs +++ b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/ValueTypeGetFieldHelperMethodOverride.cs @@ -142,11 +142,13 @@ public override bool IsVirtual } } + internal const string MetadataName = "__GetFieldHelper"; + public override string Name { get { - return "__GetFieldHelper"; + return MetadataName; } } @@ -154,7 +156,7 @@ public override string DiagnosticName { get { - return "__GetFieldHelper"; + return MetadataName; } } } diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/NoMetadataBlockingPolicy.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/NoMetadataBlockingPolicy.cs index ebb4012377edb1..67d03fe6874ea4 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/NoMetadataBlockingPolicy.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/NoMetadataBlockingPolicy.cs @@ -51,6 +51,11 @@ public override bool IsBlocked(MethodDesc method) if (ecmaMethod.OwningType == GetArrayOfTType(ecmaMethod)) return true; + // Also don't expose the ValueType.__GetFieldOverride method. + if (ecmaMethod.Name == Internal.IL.Stubs.ValueTypeGetFieldHelperMethodOverride.MetadataName + && ecmaMethod.OwningType.IsWellKnownType(WellKnownType.ValueType)) + return true; + return false; } diff --git a/src/libraries/Common/tests/System/Net/Http/HttpClientHandlerTest.Proxy.cs b/src/libraries/Common/tests/System/Net/Http/HttpClientHandlerTest.Proxy.cs index bedf1ffd70c029..3ad71643b82920 100644 --- a/src/libraries/Common/tests/System/Net/Http/HttpClientHandlerTest.Proxy.cs +++ b/src/libraries/Common/tests/System/Net/Http/HttpClientHandlerTest.Proxy.cs @@ -499,14 +499,15 @@ public async Task MultiProxy_PAC_Failover_Succeeds() string proxyConfigString = $"{failingEndPoint.Address}:{failingEndPoint.Port} {succeedingProxyServer.Uri.Host}:{succeedingProxyServer.Uri.Port}"; // Create a WinInetProxyHelper and override its values with our own. - object winInetProxyHelper = Activator.CreateInstance(typeof(HttpClient).Assembly.GetType("System.Net.Http.WinInetProxyHelper", true), true); - winInetProxyHelper.GetType().GetField("_autoConfigUrl", Reflection.BindingFlags.Instance | Reflection.BindingFlags.NonPublic).SetValue(winInetProxyHelper, null); - winInetProxyHelper.GetType().GetField("_autoDetect", Reflection.BindingFlags.Instance | Reflection.BindingFlags.NonPublic).SetValue(winInetProxyHelper, false); - winInetProxyHelper.GetType().GetField("_proxy", Reflection.BindingFlags.Instance | Reflection.BindingFlags.NonPublic).SetValue(winInetProxyHelper, proxyConfigString); - winInetProxyHelper.GetType().GetField("_proxyBypass", Reflection.BindingFlags.Instance | Reflection.BindingFlags.NonPublic).SetValue(winInetProxyHelper, null); + Type winInetProxyHelperType = Type.GetType("System.Net.Http.WinInetProxyHelper, System.Net.Http", true); + object winInetProxyHelper = Activator.CreateInstance(winInetProxyHelperType, true); + winInetProxyHelperType.GetField("_autoConfigUrl", Reflection.BindingFlags.Instance | Reflection.BindingFlags.NonPublic).SetValue(winInetProxyHelper, null); + winInetProxyHelperType.GetField("_autoDetect", Reflection.BindingFlags.Instance | Reflection.BindingFlags.NonPublic).SetValue(winInetProxyHelper, false); + winInetProxyHelperType.GetField("_proxy", Reflection.BindingFlags.Instance | Reflection.BindingFlags.NonPublic).SetValue(winInetProxyHelper, proxyConfigString); + winInetProxyHelperType.GetField("_proxyBypass", Reflection.BindingFlags.Instance | Reflection.BindingFlags.NonPublic).SetValue(winInetProxyHelper, null); // Create a HttpWindowsProxy with our custom WinInetProxyHelper. - IWebProxy httpWindowsProxy = (IWebProxy)Activator.CreateInstance(typeof(HttpClient).Assembly.GetType("System.Net.Http.HttpWindowsProxy", true), Reflection.BindingFlags.NonPublic | Reflection.BindingFlags.Instance, null, new[] { winInetProxyHelper, null }, null); + IWebProxy httpWindowsProxy = (IWebProxy)Activator.CreateInstance(Type.GetType("System.Net.Http.HttpWindowsProxy, System.Net.Http", true), Reflection.BindingFlags.NonPublic | Reflection.BindingFlags.Instance, null, new[] { winInetProxyHelper, null }, null); Task nextFailedConnection = null; diff --git a/src/libraries/Microsoft.NETCore.Platforms/tests/GenerateRuntimeGraphTests.cs b/src/libraries/Microsoft.NETCore.Platforms/tests/GenerateRuntimeGraphTests.cs index a5c378d58aeea5..bce0965cf0aa8b 100644 --- a/src/libraries/Microsoft.NETCore.Platforms/tests/GenerateRuntimeGraphTests.cs +++ b/src/libraries/Microsoft.NETCore.Platforms/tests/GenerateRuntimeGraphTests.cs @@ -14,6 +14,8 @@ namespace Microsoft.NETCore.Platforms.BuildTasks.Tests { + // MSBuild engine is not compatible with single file + [ConditionalClass(typeof(PlatformDetection), nameof(PlatformDetection.HasAssemblyFiles))] public class GenerateRuntimeGraphTests { private Log _log; diff --git a/src/libraries/Microsoft.Win32.SystemEvents/tests/SystemEvents.InvokeOnEventsThread.cs b/src/libraries/Microsoft.Win32.SystemEvents/tests/SystemEvents.InvokeOnEventsThread.cs index a0a571e7b7624b..0f4cb2200706bd 100644 --- a/src/libraries/Microsoft.Win32.SystemEvents/tests/SystemEvents.InvokeOnEventsThread.cs +++ b/src/libraries/Microsoft.Win32.SystemEvents/tests/SystemEvents.InvokeOnEventsThread.cs @@ -52,7 +52,9 @@ public void InvokeOnEventsThreadRunsOnSameThreadAsOtherEvents() } } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoNorServerCore))] + public static bool NotNanoNorServerCoreAndRemoteExecutorSupported => PlatformDetection.IsNotWindowsNanoNorServerCore && RemoteExecutor.IsSupported; + + [ConditionalFact(nameof(NotNanoNorServerCoreAndRemoteExecutorSupported))] [SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework)] [ActiveIssue("https://github.com/dotnet/runtime/issues/34360", TestPlatforms.Windows, TargetFrameworkMonikers.Netcoreapp, TestRuntimes.Mono)] public void RegisterFromSTAThreadThatGoesAway_MessageStillDelivered() diff --git a/src/libraries/System.Globalization.Calendars/tests/CalendarTestWithConfigSwitch/System.Globalization.CalendarsWithConfigSwitch.Tests.csproj b/src/libraries/System.Globalization.Calendars/tests/CalendarTestWithConfigSwitch/System.Globalization.CalendarsWithConfigSwitch.Tests.csproj index cd8e38755ac08d..20a380676b3451 100644 --- a/src/libraries/System.Globalization.Calendars/tests/CalendarTestWithConfigSwitch/System.Globalization.CalendarsWithConfigSwitch.Tests.csproj +++ b/src/libraries/System.Globalization.Calendars/tests/CalendarTestWithConfigSwitch/System.Globalization.CalendarsWithConfigSwitch.Tests.csproj @@ -6,4 +6,7 @@ + + + \ No newline at end of file diff --git a/src/libraries/System.Globalization.Calendars/tests/CalendarTestWithConfigSwitch/runtimeconfig.template.json b/src/libraries/System.Globalization.Calendars/tests/CalendarTestWithConfigSwitch/runtimeconfig.template.json deleted file mode 100644 index 1cfef3c8ff7ee0..00000000000000 --- a/src/libraries/System.Globalization.Calendars/tests/CalendarTestWithConfigSwitch/runtimeconfig.template.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "configProperties": { - "Switch.System.Globalization.EnforceJapaneseEraYearRanges": true - } -} \ No newline at end of file diff --git a/src/libraries/System.Globalization/tests/NlsTests/System.Globalization.Nls.Tests.csproj b/src/libraries/System.Globalization/tests/NlsTests/System.Globalization.Nls.Tests.csproj index 7d02e3dcc9b55a..a9aeef49807f07 100644 --- a/src/libraries/System.Globalization/tests/NlsTests/System.Globalization.Nls.Tests.csproj +++ b/src/libraries/System.Globalization/tests/NlsTests/System.Globalization.Nls.Tests.csproj @@ -7,6 +7,9 @@ $(NetCoreAppCurrent)-windows 14.0 + + + @@ -222,6 +225,9 @@ + + + diff --git a/src/libraries/System.Globalization/tests/NlsTests/runtimeconfig.template.json b/src/libraries/System.Globalization/tests/NlsTests/runtimeconfig.template.json deleted file mode 100644 index f93c6039127bd1..00000000000000 --- a/src/libraries/System.Globalization/tests/NlsTests/runtimeconfig.template.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "configProperties": { - "System.Globalization.UseNls": true - } -} diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpConnectionKeyTest.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpConnectionKeyTest.cs index 1177b6bb06b902..0517cc612d013a 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpConnectionKeyTest.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpConnectionKeyTest.cs @@ -26,12 +26,10 @@ public static IEnumerable KeyComponents() [Theory, MemberData(nameof(KeyComponents))] public void Equals_DifferentParameters_ReturnsTrueIfAllEqual(string kindString, string host, int port, string sslHostName, Uri proxyUri, string identity, bool expected) { - Assembly assembly = typeof(HttpClientHandler).Assembly; - Type connectionKindType = assembly.GetTypes().Where(t => t.Name == "HttpConnectionKind").First(); - Type poolManagerType = assembly.GetTypes().Where(t => t.Name == "HttpConnectionPoolManager").First(); - Type keyType = poolManagerType.GetNestedType("HttpConnectionKey", BindingFlags.NonPublic); - dynamic referenceKey = Activator.CreateInstance(keyType, Enum.Parse(connectionKindType, "Http"), "localhost", 80, "localhost-ssl", new Uri("http://localhost"), "domain1/userA"); - dynamic actualKey = Activator.CreateInstance(keyType, Enum.Parse(connectionKindType, kindString), host, port, sslHostName, proxyUri, identity); + Type connectionKindType = Type.GetType("System.Net.Http.HttpConnectionKind, System.Net.Http"); + Type keyType = Type.GetType("System.Net.Http.HttpConnectionPoolManager+HttpConnectionKey, System.Net.Http"); + object referenceKey = Activator.CreateInstance(keyType, Enum.Parse(connectionKindType, "Http"), "localhost", 80, "localhost-ssl", new Uri("http://localhost"), "domain1/userA"); + object actualKey = Activator.CreateInstance(keyType, Enum.Parse(connectionKindType, kindString), host, port, sslHostName, proxyUri, identity); Assert.Equal(expected, referenceKey.Equals(actualKey)); } } diff --git a/src/libraries/System.Net.Security/tests/FunctionalTests/System.Net.Security.Tests.csproj b/src/libraries/System.Net.Security/tests/FunctionalTests/System.Net.Security.Tests.csproj index 67f4711594d6fe..e00fd263ac15e6 100644 --- a/src/libraries/System.Net.Security/tests/FunctionalTests/System.Net.Security.Tests.csproj +++ b/src/libraries/System.Net.Security/tests/FunctionalTests/System.Net.Security.Tests.csproj @@ -11,6 +11,9 @@ + + + diff --git a/src/libraries/System.Net.Security/tests/FunctionalTests/default.rd.xml b/src/libraries/System.Net.Security/tests/FunctionalTests/default.rd.xml new file mode 100644 index 00000000000000..cfe89e070fc85d --- /dev/null +++ b/src/libraries/System.Net.Security/tests/FunctionalTests/default.rd.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/src/libraries/System.Reflection.TypeExtensions/tests/FieldInfoTests.cs b/src/libraries/System.Reflection.TypeExtensions/tests/FieldInfoTests.cs index 8908ae7ece0e72..865790e068d626 100644 --- a/src/libraries/System.Reflection.TypeExtensions/tests/FieldInfoTests.cs +++ b/src/libraries/System.Reflection.TypeExtensions/tests/FieldInfoTests.cs @@ -46,6 +46,10 @@ public void Properties(string name, FieldAttributes attributes, Type fieldType) public static IEnumerable GetValue_TestData() { + // Trick trimming into keeping the Empty field + if (string.Empty.Length > 0) + typeof(string).GetField("Empty"); + yield return new object[] { typeof(string), "Empty", "abc", "" }; yield return new object[] { typeof(FI_BaseClass), "_privateStringField", new FI_BaseClass(), "2" }; diff --git a/src/libraries/System.Reflection.TypeExtensions/tests/MetadataTokenTests.cs b/src/libraries/System.Reflection.TypeExtensions/tests/MetadataTokenTests.cs index 5e9d1a83a207d8..77309f734f7969 100644 --- a/src/libraries/System.Reflection.TypeExtensions/tests/MetadataTokenTests.cs +++ b/src/libraries/System.Reflection.TypeExtensions/tests/MetadataTokenTests.cs @@ -57,7 +57,7 @@ public static void ReflectionEmitType_HasMetadataToken() Assert.NotEqual(0, method.GetMetadataToken()); } - public static bool GetMetadataTokenSupported => true; + public static bool GetMetadataTokenSupported => PlatformDetection.IsMetadataTokenSupported; public static bool IsReflectionEmitSupported => PlatformDetection.IsReflectionEmitSupported; diff --git a/src/libraries/System.Reflection.TypeExtensions/tests/MethodBaseTests.cs b/src/libraries/System.Reflection.TypeExtensions/tests/MethodBaseTests.cs index 740668a9bec31c..66b8500bdffb36 100644 --- a/src/libraries/System.Reflection.TypeExtensions/tests/MethodBaseTests.cs +++ b/src/libraries/System.Reflection.TypeExtensions/tests/MethodBaseTests.cs @@ -12,7 +12,7 @@ public static IEnumerable ContainsGenericParameters_TestData() { // Methods yield return new object[] { TypeExtensions.GetMethod(typeof(NonGenericClass), nameof(NonGenericClass.TestGenericMethod), Helpers.AllFlags), true }; - yield return new object[] { TypeExtensions.GetMethod(typeof(NonGenericClass), nameof(NonGenericClass.TestGenericMethod), Helpers.AllFlags).MakeGenericMethod(typeof(int)), false }; + yield return new object[] { TypeExtensions.GetMethod(typeof(NonGenericClass), nameof(NonGenericClass.TestGenericMethod), Helpers.AllFlags).MakeGenericMethod(typeof(string)), false }; yield return new object[] { TypeExtensions.GetMethod(typeof(NonGenericClass), nameof(NonGenericClass.TestMethod), Helpers.AllFlags), false }; yield return new object[] { TypeExtensions.GetMethod(typeof(NonGenericClass), nameof(NonGenericClass.TestPartialGenericMethod), Helpers.AllFlags), true }; yield return new object[] { TypeExtensions.GetMethod(typeof(NonGenericClass), nameof(NonGenericClass.TestGenericReturnTypeMethod), Helpers.AllFlags), true }; diff --git a/src/libraries/System.Reflection.TypeExtensions/tests/ModuleTests.cs b/src/libraries/System.Reflection.TypeExtensions/tests/ModuleTests.cs index e617c50180e6cd..9017b400f280ac 100644 --- a/src/libraries/System.Reflection.TypeExtensions/tests/ModuleTests.cs +++ b/src/libraries/System.Reflection.TypeExtensions/tests/ModuleTests.cs @@ -22,7 +22,8 @@ public void GetModuleVersionId_HasModuleVersionId_BehaveConsistently() } } - [Fact] + // This calls Assembly.Load, but xUnit turn is into a LoadFrom because TinyAssembly is just a Content item in the project. + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsAssemblyLoadingSupported))] public void GetModuleVersionId_KnownAssembly_ReturnsExpected() { Module module = Assembly.Load(new AssemblyName("TinyAssembly")).ManifestModule; diff --git a/src/libraries/System.Reflection.TypeExtensions/tests/PropertyInfoTests.cs b/src/libraries/System.Reflection.TypeExtensions/tests/PropertyInfoTests.cs index b0cd7b967c5b1e..d67b52c7f85c3b 100644 --- a/src/libraries/System.Reflection.TypeExtensions/tests/PropertyInfoTests.cs +++ b/src/libraries/System.Reflection.TypeExtensions/tests/PropertyInfoTests.cs @@ -9,10 +9,19 @@ namespace System.Reflection.Tests { public class PropertyInfoTests { + public static IEnumerable Properties_TestData() + { + yield return new object[] { typeof(PI_BaseClass), nameof(PI_BaseClass.PublicGetPublicSetStaticProperty) }; + yield return new object[] { typeof(PI_BaseClass), nameof(PI_BaseClass.PublicGetPublicSetProperty) }; + + // trick trimming into keeping the Length property + if (string.Empty.Length > 0) + typeof(string).GetProperty("Length"); + yield return new object[] { typeof(string), nameof(string.Length) }; + } + [Theory] - [InlineData(typeof(PI_BaseClass), nameof(PI_BaseClass.PublicGetPublicSetStaticProperty))] - [InlineData(typeof(PI_BaseClass), nameof(PI_BaseClass.PublicGetPublicSetProperty))] - [InlineData(typeof(string), nameof(string.Length))] + [MemberData(nameof(Properties_TestData))] public void Properties(Type type, string name) { PropertyInfo property = TypeExtensions.GetProperty(type, name, Helpers.AllFlags); diff --git a/src/libraries/System.Threading.RateLimiting/tests/Infrastructure/Utils.cs b/src/libraries/System.Threading.RateLimiting/tests/Infrastructure/Utils.cs index 2897cca7b3f9f0..de62a2d6c065a9 100644 --- a/src/libraries/System.Threading.RateLimiting/tests/Infrastructure/Utils.cs +++ b/src/libraries/System.Threading.RateLimiting/tests/Infrastructure/Utils.cs @@ -15,7 +15,7 @@ internal static class Utils // Creates a DefaultPartitionedRateLimiter with the timer effectively disabled internal static PartitionedRateLimiter CreatePartitionedLimiterWithoutTimer(Func> partitioner) { - var limiterType = Assembly.GetAssembly(typeof(PartitionedRateLimiter<>)).GetType("System.Threading.RateLimiting.DefaultPartitionedRateLimiter`2"); + var limiterType = Type.GetType("System.Threading.RateLimiting.DefaultPartitionedRateLimiter`2, System.Threading.RateLimiting"); Assert.NotNull(limiterType); var genericLimiterType = limiterType.MakeGenericType(typeof(TResource), typeof(TKey)); @@ -30,10 +30,17 @@ internal static PartitionedRateLimiter CreatePartitionedLimiterWithou // Gets and runs the Heartbeat function on the DefaultPartitionedRateLimiter internal static Task RunTimerFunc(PartitionedRateLimiter limiter) { - var innerTimer = limiter.GetType().GetField("_timer", BindingFlags.NonPublic | BindingFlags.Instance); + // Use Type.GetType so that trimming can see what type we're reflecting on, but assert it's the one we got + var limiterTypeDef = Type.GetType("System.Threading.RateLimiting.DefaultPartitionedRateLimiter`2, System.Threading.RateLimiting"); + var limiterType = limiter.GetType(); + Assert.Equal(limiterTypeDef, limiterType.GetGenericTypeDefinition()); + if (string.Empty.Length > 0) + limiterType = limiterTypeDef; + + var innerTimer = limiterType.GetField("_timer", BindingFlags.NonPublic | BindingFlags.Instance); Assert.NotNull(innerTimer); - var timerLoopMethod = limiter.GetType().GetMethod("Heartbeat", BindingFlags.NonPublic | BindingFlags.Instance); + var timerLoopMethod = limiterType.GetMethod("Heartbeat", BindingFlags.NonPublic | BindingFlags.Instance); Assert.NotNull(timerLoopMethod); return (Task)timerLoopMethod.Invoke(limiter, Array.Empty()); diff --git a/src/libraries/tests.proj b/src/libraries/tests.proj index 031835ef133ad6..9ef58ead2f339f 100644 --- a/src/libraries/tests.proj +++ b/src/libraries/tests.proj @@ -488,12 +488,10 @@ - - @@ -508,9 +506,7 @@ - - @@ -531,8 +527,6 @@ - - @@ -542,8 +536,6 @@ - -