diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IEnumerableConverterFactoryHelpers.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IEnumerableConverterFactoryHelpers.cs index c434444f5ab7bd..819de1fec2037c 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IEnumerableConverterFactoryHelpers.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IEnumerableConverterFactoryHelpers.cs @@ -40,10 +40,9 @@ internal static class IEnumerableConverterFactoryHelpers private const string ImmutableSortedDictionaryTypeName = "System.Collections.Immutable.ImmutableSortedDictionary"; private const string CreateRangeMethodName = "CreateRange"; - private const string CreateRangeMethodNameForEnumerable = "CreateRange`1"; - private const string CreateRangeMethodNameForDictionary = "CreateRange`2"; - private const string ImmutableCollectionsAssembly = "System.Collections.Immutable"; + // Don't use DynamicDependency attributes to the Immutable Collection types so they can be trimmed in applications that don't use Immutable Collections. + internal const string ImmutableConvertersUnreferencedCodeMessage = "System.Collections.Immutable converters use Reflection to find and create Immutable Collection types, which requires unreferenced code."; internal static Type? GetCompatibleGenericBaseClass(this Type type, Type baseType) { @@ -151,16 +150,7 @@ public static bool IsImmutableEnumerableType(this Type type) } } - [DynamicDependency(CreateRangeMethodNameForEnumerable, ImmutableArrayTypeName, ImmutableCollectionsAssembly)] - [DynamicDependency(CreateRangeMethodNameForEnumerable, ImmutableListTypeName, ImmutableCollectionsAssembly)] - [DynamicDependency(CreateRangeMethodNameForEnumerable, ImmutableStackTypeName, ImmutableCollectionsAssembly)] - [DynamicDependency(CreateRangeMethodNameForEnumerable, ImmutableQueueTypeName, ImmutableCollectionsAssembly)] - [DynamicDependency(CreateRangeMethodNameForEnumerable, ImmutableSortedSetTypeName, ImmutableCollectionsAssembly)] - [DynamicDependency(CreateRangeMethodNameForEnumerable, ImmutableHashSetTypeName, ImmutableCollectionsAssembly)] - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2075:UnrecognizedReflectionPattern", - Justification = "The CreateRange method is preserved by the DynamicDependency attribute.")] - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2060:MakeGenericMethod", - Justification = "Immutable collections don't have trimming annotations.")] + [RequiresUnreferencedCode(ImmutableConvertersUnreferencedCodeMessage)] public static MethodInfo GetImmutableEnumerableCreateRangeMethod(this Type type, Type elementType) { Type? constructingType = GetImmutableEnumerableConstructingType(type); @@ -183,12 +173,7 @@ public static MethodInfo GetImmutableEnumerableCreateRangeMethod(this Type type, return null!; } - [DynamicDependency(CreateRangeMethodNameForDictionary, ImmutableDictionaryTypeName, ImmutableCollectionsAssembly)] - [DynamicDependency(CreateRangeMethodNameForDictionary, ImmutableSortedDictionaryTypeName, ImmutableCollectionsAssembly)] - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2075:UnrecognizedReflectionPattern", - Justification = "The CreateRange method is preserved by the DynamicDependency attribute.")] - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2060:MakeGenericMethod", - Justification = "Immutable collections don't have trimming annotations.")] + [RequiresUnreferencedCode(ImmutableConvertersUnreferencedCodeMessage)] public static MethodInfo GetImmutableDictionaryCreateRangeMethod(this Type type, Type keyType, Type valueType) { Type? constructingType = GetImmutableDictionaryConstructingType(type); @@ -211,9 +196,7 @@ public static MethodInfo GetImmutableDictionaryCreateRangeMethod(this Type type, return null!; } - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", - Justification = "Json can't take a direct dependency on Collections.Immutable." + - "The types used here will be preserved by the DynamicDependency attributes on the only caller - GetImmutableEnumerableCreateRangeMethod.")] + [RequiresUnreferencedCode(ImmutableConvertersUnreferencedCodeMessage)] private static Type? GetImmutableEnumerableConstructingType(Type type) { Debug.Assert(type.IsImmutableEnumerableType()); @@ -257,9 +240,7 @@ public static MethodInfo GetImmutableDictionaryCreateRangeMethod(this Type type, return underlyingType.Assembly.GetType(constructingTypeName); } - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", - Justification = "Json can't take a direct dependency on Collections.Immutable." + - "The types used here will be preserved by the DynamicDependency attributes on the only caller - GetImmutableDictionaryCreateRangeMethod.")] + [RequiresUnreferencedCode(ImmutableConvertersUnreferencedCodeMessage)] private static Type? GetImmutableDictionaryConstructingType(Type type) { Debug.Assert(type.IsImmutableDictionaryType()); diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ImmutableDictionaryOfTKeyTValueConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ImmutableDictionaryOfTKeyTValueConverter.cs index b077f456d82f28..7923890979b39c 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ImmutableDictionaryOfTKeyTValueConverter.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ImmutableDictionaryOfTKeyTValueConverter.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Text.Json.Serialization.Metadata; namespace System.Text.Json.Serialization.Converters @@ -11,6 +12,11 @@ internal sealed class ImmutableDictionaryOfTKeyTValueConverter where TKey : notnull { + [RequiresUnreferencedCode(IEnumerableConverterFactoryHelpers.ImmutableConvertersUnreferencedCodeMessage)] + public ImmutableDictionaryOfTKeyTValueConverter() + { + } + protected override void Add(TKey key, in TValue value, JsonSerializerOptions options, ref ReadStack state) { ((Dictionary)state.Current.ReturnValue!)[key] = value; @@ -23,6 +29,8 @@ protected override void CreateCollection(ref Utf8JsonReader reader, ref ReadStac state.Current.ReturnValue = new Dictionary(); } + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", + Justification = "The ctor is marked RequiresUnreferencedCode.")] protected override void ConvertCollection(ref ReadStack state, JsonSerializerOptions options) { JsonTypeInfo typeInfo = state.Current.JsonTypeInfo; diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ImmutableEnumerableOfTConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ImmutableEnumerableOfTConverter.cs index 8c2ad3a53c4120..d65807bf25c61e 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ImmutableEnumerableOfTConverter.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ImmutableEnumerableOfTConverter.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Text.Json.Serialization.Metadata; namespace System.Text.Json.Serialization.Converters @@ -10,6 +11,11 @@ internal sealed class ImmutableEnumerableOfTConverter : IEnumerableDefaultConverter where TCollection : IEnumerable { + [RequiresUnreferencedCode(IEnumerableConverterFactoryHelpers.ImmutableConvertersUnreferencedCodeMessage)] + public ImmutableEnumerableOfTConverter() + { + } + protected override void Add(in TElement value, ref ReadStack state) { ((List)state.Current.ReturnValue!).Add(value); @@ -22,6 +28,8 @@ protected override void CreateCollection(ref Utf8JsonReader reader, ref ReadStac state.Current.ReturnValue = new List(); } + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", + Justification = "The ctor is marked RequiresUnreferencedCode.")] protected override void ConvertCollection(ref ReadStack state, JsonSerializerOptions options) { JsonTypeInfo typeInfo = state.Current.JsonTypeInfo; diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/MemberAccessor.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/MemberAccessor.cs index f4f934ccf7e9a2..d246b45bf9a003 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/MemberAccessor.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/MemberAccessor.cs @@ -19,8 +19,10 @@ public abstract JsonTypeInfo.ParameterizedConstructorDelegate CreateAddMethodDelegate<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] TCollection>(); + [RequiresUnreferencedCode(IEnumerableConverterFactoryHelpers.ImmutableConvertersUnreferencedCodeMessage)] public abstract Func, TCollection> CreateImmutableEnumerableCreateRangeDelegate(); + [RequiresUnreferencedCode(IEnumerableConverterFactoryHelpers.ImmutableConvertersUnreferencedCodeMessage)] public abstract Func>, TCollection> CreateImmutableDictionaryCreateRangeDelegate(); public abstract Func CreatePropertyGetter(PropertyInfo propertyInfo); diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/ReflectionEmitMemberAccessor.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/ReflectionEmitMemberAccessor.cs index 24e0b20927b734..2276b025979c40 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/ReflectionEmitMemberAccessor.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/ReflectionEmitMemberAccessor.cs @@ -172,10 +172,12 @@ private static DynamicMethod CreateAddMethodDelegate( return dynamicMethod; } + [RequiresUnreferencedCode(IEnumerableConverterFactoryHelpers.ImmutableConvertersUnreferencedCodeMessage)] public override Func, TCollection> CreateImmutableEnumerableCreateRangeDelegate() => CreateDelegate, TCollection>>( CreateImmutableEnumerableCreateRangeDelegate(typeof(TCollection), typeof(TElement), typeof(IEnumerable))); + [RequiresUnreferencedCode(IEnumerableConverterFactoryHelpers.ImmutableConvertersUnreferencedCodeMessage)] private static DynamicMethod CreateImmutableEnumerableCreateRangeDelegate(Type collectionType, Type elementType, Type enumerableType) { MethodInfo realMethod = collectionType.GetImmutableEnumerableCreateRangeMethod(elementType); @@ -196,10 +198,12 @@ private static DynamicMethod CreateImmutableEnumerableCreateRangeDelegate(Type c return dynamicMethod; } + [RequiresUnreferencedCode(IEnumerableConverterFactoryHelpers.ImmutableConvertersUnreferencedCodeMessage)] public override Func>, TCollection> CreateImmutableDictionaryCreateRangeDelegate() => CreateDelegate>, TCollection>>( CreateImmutableDictionaryCreateRangeDelegate(typeof(TCollection), typeof(TKey), typeof(TValue), typeof(IEnumerable>))); + [RequiresUnreferencedCode(IEnumerableConverterFactoryHelpers.ImmutableConvertersUnreferencedCodeMessage)] private static DynamicMethod CreateImmutableDictionaryCreateRangeDelegate(Type collectionType, Type keyType, Type valueType, Type enumerableType) { MethodInfo realMethod = collectionType.GetImmutableDictionaryCreateRangeMethod(keyType, valueType); diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/ReflectionMemberAccessor.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/ReflectionMemberAccessor.cs index b2e7e961bb26d3..2a8ccd166eaf1e 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/ReflectionMemberAccessor.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/ReflectionMemberAccessor.cs @@ -124,6 +124,7 @@ public override JsonTypeInfo.ParameterizedConstructorDelegate, TCollection> CreateImmutableEnumerableCreateRangeDelegate() { MethodInfo createRange = typeof(TCollection).GetImmutableEnumerableCreateRangeMethod(typeof(TElement)); @@ -131,6 +132,7 @@ public override Func, TCollection> CreateImmutableEnumerab typeof(Func, TCollection>)); } + [RequiresUnreferencedCode(IEnumerableConverterFactoryHelpers.ImmutableConvertersUnreferencedCodeMessage)] public override Func>, TCollection> CreateImmutableDictionaryCreateRangeDelegate() { MethodInfo createRange = typeof(TCollection).GetImmutableDictionaryCreateRangeMethod(typeof(TKey), typeof(TValue)); diff --git a/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/TrimmingTests/Collections/IImmutableDictionary.cs b/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/TrimmingTests/Collections/IImmutableDictionary.cs deleted file mode 100644 index 15156f8c62b9f9..00000000000000 --- a/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/TrimmingTests/Collections/IImmutableDictionary.cs +++ /dev/null @@ -1,26 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System.Collections.Immutable; -using System.Text.Json; - -namespace SerializerTrimmingTest -{ - /// - /// Tests that the serializer's warm up routine for (de)serializing IImmutableDictionary is linker-safe. - /// - internal class Program - { - static int Main(string[] args) - { - string json = @"{""Key"":1}"; - object obj = JsonSerializer.Deserialize(json, typeof(IImmutableDictionary)); - if (!(TestHelper.AssertCollectionAndSerialize>(obj, json))) - { - return -1; - } - - return 100; - } - } -} diff --git a/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/TrimmingTests/Collections/IImmutableList.cs b/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/TrimmingTests/Collections/IImmutableList.cs deleted file mode 100644 index 608a2dd496ebce..00000000000000 --- a/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/TrimmingTests/Collections/IImmutableList.cs +++ /dev/null @@ -1,26 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System.Collections.Immutable; -using System.Text.Json; - -namespace SerializerTrimmingTest -{ - /// - /// Tests that the serializer's warm up routine for (de)serializing IImmutableList is linker-safe. - /// - internal class Program - { - static int Main(string[] args) - { - string json = "[1]"; - object obj = JsonSerializer.Deserialize(json, typeof(IImmutableList)); - if (!(TestHelper.AssertCollectionAndSerialize>(obj, json))) - { - return -1; - } - - return 100; - } - } -} diff --git a/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/TrimmingTests/Collections/IImmutableQueue.cs b/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/TrimmingTests/Collections/IImmutableQueue.cs deleted file mode 100644 index b8bcfafa4a13ad..00000000000000 --- a/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/TrimmingTests/Collections/IImmutableQueue.cs +++ /dev/null @@ -1,26 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System.Collections.Immutable; -using System.Text.Json; - -namespace SerializerTrimmingTest -{ - /// - /// Tests that the serializer's warm up routine for (de)serializing IImmutableQueue is linker-safe. - /// - internal class Program - { - static int Main(string[] args) - { - string json = "[1]"; - object obj = JsonSerializer.Deserialize(json, typeof(IImmutableQueue)); - if (!(TestHelper.AssertCollectionAndSerialize>(obj, json))) - { - return -1; - } - - return 100; - } - } -} diff --git a/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/TrimmingTests/Collections/IImmutableSet.cs b/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/TrimmingTests/Collections/IImmutableSet.cs deleted file mode 100644 index 836d3fcd849b23..00000000000000 --- a/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/TrimmingTests/Collections/IImmutableSet.cs +++ /dev/null @@ -1,26 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System.Collections.Immutable; -using System.Text.Json; - -namespace SerializerTrimmingTest -{ - /// - /// Tests that the serializer's warm up routine for (de)serializing IImmutableSet is linker-safe. - /// - internal class Program - { - static int Main(string[] args) - { - string json = "[1]"; - object obj = JsonSerializer.Deserialize(json, typeof(IImmutableSet)); - if (!(TestHelper.AssertCollectionAndSerialize>(obj, json))) - { - return -1; - } - - return 100; - } - } -} diff --git a/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/TrimmingTests/Collections/IImmutableStack.cs b/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/TrimmingTests/Collections/IImmutableStack.cs deleted file mode 100644 index 4cf3e789309935..00000000000000 --- a/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/TrimmingTests/Collections/IImmutableStack.cs +++ /dev/null @@ -1,26 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System.Collections.Immutable; -using System.Text.Json; - -namespace SerializerTrimmingTest -{ - /// - /// Tests that the serializer's warm up routine for (de)serializing IImmutableStack is linker-safe. - /// - internal class Program - { - static int Main(string[] args) - { - string json = "[1]"; - object obj = JsonSerializer.Deserialize(json, typeof(IImmutableStack)); - if (!(TestHelper.AssertCollectionAndSerialize>(obj, json))) - { - return -1; - } - - return 100; - } - } -} diff --git a/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/TrimmingTests/Collections/ImmutableArray.cs b/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/TrimmingTests/Collections/ImmutableArray.cs deleted file mode 100644 index 386b768021e42a..00000000000000 --- a/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/TrimmingTests/Collections/ImmutableArray.cs +++ /dev/null @@ -1,26 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System.Collections.Immutable; -using System.Text.Json; - -namespace SerializerTrimmingTest -{ - /// - /// Tests that the serializer's warm up routine for (de)serializing ImmutableArray is linker-safe. - /// - internal class Program - { - static int Main(string[] args) - { - string json = "[1]"; - object obj = JsonSerializer.Deserialize(json, typeof(ImmutableArray)); - if (!(TestHelper.AssertCollectionAndSerialize>(obj, json))) - { - return -1; - } - - return 100; - } - } -} diff --git a/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/TrimmingTests/Collections/ImmutableDictionary.cs b/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/TrimmingTests/Collections/ImmutableDictionary.cs deleted file mode 100644 index 194bc4a0a5f44c..00000000000000 --- a/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/TrimmingTests/Collections/ImmutableDictionary.cs +++ /dev/null @@ -1,26 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System.Collections.Immutable; -using System.Text.Json; - -namespace SerializerTrimmingTest -{ - /// - /// Tests that the serializer's warm up routine for (de)serializing ImmutableDictionary is linker-safe. - /// - internal class Program - { - static int Main(string[] args) - { - string json = @"{""Key"":1}"; - object obj = JsonSerializer.Deserialize(json, typeof(ImmutableDictionary)); - if (!(TestHelper.AssertCollectionAndSerialize>(obj, json))) - { - return -1; - } - - return 100; - } - } -} diff --git a/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/TrimmingTests/Collections/ImmutableHashSet.cs b/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/TrimmingTests/Collections/ImmutableHashSet.cs deleted file mode 100644 index 9991be7e8cef60..00000000000000 --- a/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/TrimmingTests/Collections/ImmutableHashSet.cs +++ /dev/null @@ -1,26 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System.Collections.Immutable; -using System.Text.Json; - -namespace SerializerTrimmingTest -{ - /// - /// Tests that the serializer's warm up routine for (de)serializing ImmutableHashSet is linker-safe. - /// - internal class Program - { - static int Main(string[] args) - { - string json = "[1]"; - object obj = JsonSerializer.Deserialize(json, typeof(ImmutableHashSet)); - if (!(TestHelper.AssertCollectionAndSerialize>(obj, json))) - { - return -1; - } - - return 100; - } - } -} diff --git a/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/TrimmingTests/Collections/ImmutableList.cs b/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/TrimmingTests/Collections/ImmutableList.cs deleted file mode 100644 index 31562cf01be071..00000000000000 --- a/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/TrimmingTests/Collections/ImmutableList.cs +++ /dev/null @@ -1,26 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System.Collections.Immutable; -using System.Text.Json; - -namespace SerializerTrimmingTest -{ - /// - /// Tests that the serializer's warm up routine for (de)serializing ImmutableList is linker-safe. - /// - internal class Program - { - static int Main(string[] args) - { - string json = "[1]"; - object obj = JsonSerializer.Deserialize(json, typeof(ImmutableList)); - if (!(TestHelper.AssertCollectionAndSerialize>(obj, json))) - { - return -1; - } - - return 100; - } - } -} diff --git a/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/TrimmingTests/Collections/ImmutableQueue.cs b/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/TrimmingTests/Collections/ImmutableQueue.cs deleted file mode 100644 index 4c3dfde94d228a..00000000000000 --- a/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/TrimmingTests/Collections/ImmutableQueue.cs +++ /dev/null @@ -1,26 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System.Collections.Immutable; -using System.Text.Json; - -namespace SerializerTrimmingTest -{ - /// - /// Tests that the serializer's warm up routine for (de)serializing ImmutableQueue is linker-safe. - /// - internal class Program - { - static int Main(string[] args) - { - string json = "[1]"; - object obj = JsonSerializer.Deserialize(json, typeof(ImmutableQueue)); - if (!(TestHelper.AssertCollectionAndSerialize>(obj, json))) - { - return -1; - } - - return 100; - } - } -} diff --git a/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/TrimmingTests/Collections/ImmutableSortedDictionary.cs b/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/TrimmingTests/Collections/ImmutableSortedDictionary.cs deleted file mode 100644 index 44f58831e104db..00000000000000 --- a/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/TrimmingTests/Collections/ImmutableSortedDictionary.cs +++ /dev/null @@ -1,26 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System.Collections.Immutable; -using System.Text.Json; - -namespace SerializerTrimmingTest -{ - /// - /// Tests that the serializer's warm up routine for (de)serializing ImmutableSortedDictionary is linker-safe. - /// - internal class Program - { - static int Main(string[] args) - { - string json = @"{""Key"":1}"; - object obj = JsonSerializer.Deserialize(json, typeof(ImmutableSortedDictionary)); - if (!(TestHelper.AssertCollectionAndSerialize>(obj, json))) - { - return -1; - } - - return 100; - } - } -} diff --git a/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/TrimmingTests/Collections/ImmutableSortedSet.cs b/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/TrimmingTests/Collections/ImmutableSortedSet.cs deleted file mode 100644 index b938332034d037..00000000000000 --- a/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/TrimmingTests/Collections/ImmutableSortedSet.cs +++ /dev/null @@ -1,26 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System.Collections.Immutable; -using System.Text.Json; - -namespace SerializerTrimmingTest -{ - /// - /// Tests that the serializer's warm up routine for (de)serializing ImmutableSortedSet is linker-safe. - /// - internal class Program - { - static int Main(string[] args) - { - string json = "[1]"; - object obj = JsonSerializer.Deserialize(json, typeof(ImmutableSortedSet)); - if (!(TestHelper.AssertCollectionAndSerialize>(obj, json))) - { - return -1; - } - - return 100; - } - } -} diff --git a/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/TrimmingTests/Collections/ImmutableStack.cs b/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/TrimmingTests/Collections/ImmutableStack.cs deleted file mode 100644 index 3056d9cda40b18..00000000000000 --- a/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/TrimmingTests/Collections/ImmutableStack.cs +++ /dev/null @@ -1,26 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System.Collections.Immutable; -using System.Text.Json; - -namespace SerializerTrimmingTest -{ - /// - /// Tests that the serializer's warm up routine for (de)serializing ImmutableStack is linker-safe. - /// - internal class Program - { - static int Main(string[] args) - { - string json = "[1]"; - object obj = JsonSerializer.Deserialize(json, typeof(ImmutableStack)); - if (!(TestHelper.AssertCollectionAndSerialize>(obj, json))) - { - return -1; - } - - return 100; - } - } -} diff --git a/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/TrimmingTests/System.Text.Json.TrimmingTests.proj b/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/TrimmingTests/System.Text.Json.TrimmingTests.proj index ae1307bd108f26..97ef79d02f71a4 100644 --- a/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/TrimmingTests/System.Text.Json.TrimmingTests.proj +++ b/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/TrimmingTests/System.Text.Json.TrimmingTests.proj @@ -38,51 +38,12 @@ Helper.cs - - Helper.cs - - - Helper.cs - - - Helper.cs - - - Helper.cs - - - Helper.cs - Helper.cs Helper.cs - - Helper.cs - - - Helper.cs - - - Helper.cs - - - Helper.cs - - - Helper.cs - - - Helper.cs - - - Helper.cs - - - Helper.cs - Helper.cs