diff --git a/src/libraries/System.Runtime/tests/System/Reflection/NullabilityInfoContextTests.cs b/src/libraries/System.Runtime/tests/System/Reflection/NullabilityInfoContextTests.cs index d67357b9e279ba..deb55e01d9b675 100644 --- a/src/libraries/System.Runtime/tests/System/Reflection/NullabilityInfoContextTests.cs +++ b/src/libraries/System.Runtime/tests/System/Reflection/NullabilityInfoContextTests.cs @@ -17,8 +17,7 @@ public class NullabilityInfoContextTests private static readonly NullabilityInfoContext nullabilityContext = new NullabilityInfoContext(); private static readonly Type testType = typeof(TypeWithNotNullContext); private static readonly Type genericType = typeof(GenericTest); - private static readonly Type stringType = typeof(string); - private static readonly BindingFlags flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static; + private const BindingFlags flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static; public static IEnumerable FieldTestData() { @@ -705,7 +704,7 @@ public static IEnumerable StringTypeTestData() [MemberData(nameof(StringTypeTestData))] public void NullablePublicOnlyStringTypeTest(string methodName, NullabilityState param1State, NullabilityState param2State, NullabilityState param3State, Type[] types) { - ParameterInfo[] parameters = stringType.GetMethod(methodName, flags, types)!.GetParameters(); + ParameterInfo[] parameters = typeof(string).GetMethod(methodName, flags, types)!.GetParameters(); NullabilityInfo param1 = nullabilityContext.Create(parameters[0]); NullabilityInfo param2 = nullabilityContext.Create(parameters[1]); NullabilityInfo param3 = nullabilityContext.Create(parameters[2]); diff --git a/src/libraries/System.Runtime/tests/System/Text/ASCIIUtilityTests.cs b/src/libraries/System.Runtime/tests/System/Text/ASCIIUtilityTests.cs index 54a86110f40931..6636bf09eeb5bd 100644 --- a/src/libraries/System.Runtime/tests/System/Text/ASCIIUtilityTests.cs +++ b/src/libraries/System.Runtime/tests/System/Text/ASCIIUtilityTests.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Buffers; +using System.Diagnostics.CodeAnalysis; using System.Numerics; using System.Reflection; using System.Runtime.InteropServices; @@ -427,9 +428,10 @@ private static int CallWidenAsciiToUtf16(ReadOnlySpan ascii, Span ut } } + [return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.NonPublicMethods)] private static Type GetAsciiUtilityType() { - return typeof(object).Assembly.GetType("System.Text.ASCIIUtility"); + return Type.GetType("System.Text.ASCIIUtility, System.Private.CoreLib"); } private sealed class UnsafeLazyDelegate where TDelegate : Delegate diff --git a/src/libraries/System.Runtime/tests/System/Text/Latin1UtilityTests.cs b/src/libraries/System.Runtime/tests/System/Text/Latin1UtilityTests.cs index c447431b5db149..8320ab8f320707 100644 --- a/src/libraries/System.Runtime/tests/System/Text/Latin1UtilityTests.cs +++ b/src/libraries/System.Runtime/tests/System/Text/Latin1UtilityTests.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Buffers; +using System.Diagnostics.CodeAnalysis; using System.Numerics; using System.Reflection; using System.Runtime.InteropServices; @@ -325,9 +326,10 @@ private static void CallWidenLatin1ToUtf16(ReadOnlySpan latin1, Span } } + [return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.NonPublicMethods)] private static Type GetLatin1UtilityType() { - return typeof(object).Assembly.GetType("System.Text.Latin1Utility"); + return Type.GetType("System.Text.Latin1Utility, System.Private.CoreLib"); } private sealed class UnsafeLazyDelegate where TDelegate : class diff --git a/src/libraries/System.Runtime/tests/System/Text/Unicode/Utf16UtilityTests.ValidateChars.cs b/src/libraries/System.Runtime/tests/System/Text/Unicode/Utf16UtilityTests.ValidateChars.cs index d9c07161add235..9229fd32126d11 100644 --- a/src/libraries/System.Runtime/tests/System/Text/Unicode/Utf16UtilityTests.ValidateChars.cs +++ b/src/libraries/System.Runtime/tests/System/Text/Unicode/Utf16UtilityTests.ValidateChars.cs @@ -248,7 +248,7 @@ private static Lazy CreateGetPointerToFirstInva { return new Lazy(() => { - Type utf16UtilityType = typeof(Utf8).Assembly.GetType("System.Text.Unicode.Utf16Utility"); + Type utf16UtilityType = Type.GetType("System.Text.Unicode.Utf16Utility, System.Private.CoreLib"); if (utf16UtilityType is null) { diff --git a/src/libraries/System.Runtime/tests/System/Text/Unicode/Utf8UtilityTests.ValidateBytes.cs b/src/libraries/System.Runtime/tests/System/Text/Unicode/Utf8UtilityTests.ValidateBytes.cs index 3668d191bf6ceb..db701828ab657a 100644 --- a/src/libraries/System.Runtime/tests/System/Text/Unicode/Utf8UtilityTests.ValidateBytes.cs +++ b/src/libraries/System.Runtime/tests/System/Text/Unicode/Utf8UtilityTests.ValidateBytes.cs @@ -396,7 +396,7 @@ private static Lazy CreateGetPointerToFirstInva { return new Lazy(() => { - Type utf8UtilityType = typeof(Utf8).Assembly.GetType("System.Text.Unicode.Utf8Utility"); + Type utf8UtilityType = Type.GetType("System.Text.Unicode.Utf8Utility, System.Private.CoreLib"); if (utf8UtilityType is null) {