From 4d501d90ec35ae9872e711760cead299e2da22bf Mon Sep 17 00:00:00 2001 From: Adam Sitnik Date: Mon, 2 Sep 2024 14:29:12 +0200 Subject: [PATCH] BinaryFormatter tests should be skipped only on AOT, WASM and Mobile (#106858) * respect AppContext switch (which is currently enabled for all projects in the root Directory.Build.props file) * add project reference to all test projects that need working BF (and were being skipped for a while) * adjust to changes from #104202: EqualityComparer.Default is mapped to StringEqualityComparer, but serialized as GenericEqualityComparer --- .../TestUtilities/System/PlatformDetection.cs | 18 ++---------------- ...rosoft.Extensions.Hosting.Unit.Tests.csproj | 7 +++++++ .../System.Collections.NonGeneric.Tests.csproj | 5 +++++ ...System.Collections.Specialized.Tests.csproj | 5 +++++ .../Generic/Dictionary/Dictionary.Tests.cs | 7 +++++++ .../Generic/HashSet/HashSet.Generic.Tests.cs | 7 +++++++ .../tests/System.Collections.Tests.csproj | 6 ++++++ ...tem.ComponentModel.Annotations.Tests.csproj | 5 +++++ ...stem.ComponentModel.Primitives.Tests.csproj | 5 +++++ ...m.ComponentModel.TypeConverter.Tests.csproj | 4 ++++ ...iguration.ConfigurationManager.Tests.csproj | 6 ++++++ .../tests/System.Data.Common.Tests.csproj | 5 +++++ .../tests/System.Net.Requests.Tests.csproj | 4 ++++ .../System.Net.Security.Tests.csproj | 4 ++++ .../tests/System.ObjectModel.Tests.csproj | 5 +++++ .../System.Reflection.Metadata.Tests.csproj | 6 ++++++ ...ntime.Serialization.Primitives.Tests.csproj | 5 +++++ ...stem.Resources.ResourceManager.Tests.csproj | 4 ++++ .../System.Runtime.Tests.csproj | 4 ++++ .../System.Security.Cryptography.Tests.csproj | 4 ++++ ...System.Text.RegularExpressions.Tests.csproj | 5 +++++ .../System.Threading.Channels.Tests.csproj | 4 ++++ 22 files changed, 109 insertions(+), 16 deletions(-) diff --git a/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs b/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs index 66725fe6f4ea2..d35885ae25508 100644 --- a/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs +++ b/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs @@ -737,22 +737,8 @@ private static bool DetermineBinaryFormatterSupport() return false; } - Assembly assembly = typeof(System.Runtime.Serialization.Formatters.Binary.BinaryFormatter).Assembly; - AssemblyName name = assembly.GetName(); - Version assemblyVersion = name.Version; - - bool isSupported = true; - - // Version 8.1 is the version in the shared runtime (.NET 9+) that has the type disabled with no config. - // Assembly versions beyond 8.1 are the fully functional version from NuGet. - // Assembly versions before 8.1 probably won't be encountered, since that's the past. - - if (assemblyVersion.Major == 8 && assemblyVersion.Minor == 1) - { - isSupported = false; - } - - return isSupported; + return AppContext.TryGetSwitch("System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization", out bool isBinaryFormatterEnabled) + && isBinaryFormatterEnabled; } } } diff --git a/src/libraries/Microsoft.Extensions.Hosting/tests/UnitTests/Microsoft.Extensions.Hosting.Unit.Tests.csproj b/src/libraries/Microsoft.Extensions.Hosting/tests/UnitTests/Microsoft.Extensions.Hosting.Unit.Tests.csproj index 494c88fba4931..962f3f02fca83 100644 --- a/src/libraries/Microsoft.Extensions.Hosting/tests/UnitTests/Microsoft.Extensions.Hosting.Unit.Tests.csproj +++ b/src/libraries/Microsoft.Extensions.Hosting/tests/UnitTests/Microsoft.Extensions.Hosting.Unit.Tests.csproj @@ -19,4 +19,11 @@ + + + + + diff --git a/src/libraries/System.Collections.NonGeneric/tests/System.Collections.NonGeneric.Tests.csproj b/src/libraries/System.Collections.NonGeneric/tests/System.Collections.NonGeneric.Tests.csproj index 69a3250dd1597..6b8a633698e6e 100644 --- a/src/libraries/System.Collections.NonGeneric/tests/System.Collections.NonGeneric.Tests.csproj +++ b/src/libraries/System.Collections.NonGeneric/tests/System.Collections.NonGeneric.Tests.csproj @@ -44,5 +44,10 @@ + + + diff --git a/src/libraries/System.Collections.Specialized/tests/System.Collections.Specialized.Tests.csproj b/src/libraries/System.Collections.Specialized/tests/System.Collections.Specialized.Tests.csproj index d0e1a252098bd..364fd2adff71d 100644 --- a/src/libraries/System.Collections.Specialized/tests/System.Collections.Specialized.Tests.csproj +++ b/src/libraries/System.Collections.Specialized/tests/System.Collections.Specialized.Tests.csproj @@ -75,5 +75,10 @@ + + + diff --git a/src/libraries/System.Collections/tests/Generic/Dictionary/Dictionary.Tests.cs b/src/libraries/System.Collections/tests/Generic/Dictionary/Dictionary.Tests.cs index d7674f24de7eb..02a5a89db5c33 100644 --- a/src/libraries/System.Collections/tests/Generic/Dictionary/Dictionary.Tests.cs +++ b/src/libraries/System.Collections/tests/Generic/Dictionary/Dictionary.Tests.cs @@ -452,6 +452,13 @@ private static void TestComparerSerialization(IEqualityComparer equalityCo s.Position = 0; dict = (Dictionary)bf.Deserialize(s); + if (equalityComparer.Equals(EqualityComparer.Default)) + { + // EqualityComparer.Default is mapped to StringEqualityComparer, but serialized as GenericEqualityComparer + Assert.Equal("System.Collections.Generic.GenericEqualityComparer`1[System.String]", dict.Comparer.GetType().ToString()); + return; + } + if (internalTypeName == null) { Assert.IsType(equalityComparer.GetType(), dict.Comparer); diff --git a/src/libraries/System.Collections/tests/Generic/HashSet/HashSet.Generic.Tests.cs b/src/libraries/System.Collections/tests/Generic/HashSet/HashSet.Generic.Tests.cs index e3d4829cdaba1..25a4803a5d14d 100644 --- a/src/libraries/System.Collections/tests/Generic/HashSet/HashSet.Generic.Tests.cs +++ b/src/libraries/System.Collections/tests/Generic/HashSet/HashSet.Generic.Tests.cs @@ -886,6 +886,13 @@ static void TestComparerSerialization(IEqualityComparer eq s.Position = 0; set = (HashSet)bf.Deserialize(s); + if (equalityComparer.Equals(EqualityComparer.Default)) + { + // EqualityComparer.Default is mapped to StringEqualityComparer, but serialized as GenericEqualityComparer + Assert.Equal("System.Collections.Generic.GenericEqualityComparer`1[System.String]", set.Comparer.GetType().ToString()); + return; + } + if (internalTypeName == null) { Assert.IsType(equalityComparer.GetType(), set.Comparer); diff --git a/src/libraries/System.Collections/tests/System.Collections.Tests.csproj b/src/libraries/System.Collections/tests/System.Collections.Tests.csproj index 83a763207a85c..7c03f82de3934 100644 --- a/src/libraries/System.Collections/tests/System.Collections.Tests.csproj +++ b/src/libraries/System.Collections/tests/System.Collections.Tests.csproj @@ -4,6 +4,12 @@ true true + + + + diff --git a/src/libraries/System.ComponentModel.Annotations/tests/System.ComponentModel.Annotations.Tests.csproj b/src/libraries/System.ComponentModel.Annotations/tests/System.ComponentModel.Annotations.Tests.csproj index a7415591d315b..9d330b2beeb27 100644 --- a/src/libraries/System.ComponentModel.Annotations/tests/System.ComponentModel.Annotations.Tests.csproj +++ b/src/libraries/System.ComponentModel.Annotations/tests/System.ComponentModel.Annotations.Tests.csproj @@ -48,5 +48,10 @@ + + + diff --git a/src/libraries/System.ComponentModel.Primitives/tests/System.ComponentModel.Primitives.Tests.csproj b/src/libraries/System.ComponentModel.Primitives/tests/System.ComponentModel.Primitives.Tests.csproj index 80d60eb2991f4..21017a070becb 100644 --- a/src/libraries/System.ComponentModel.Primitives/tests/System.ComponentModel.Primitives.Tests.csproj +++ b/src/libraries/System.ComponentModel.Primitives/tests/System.ComponentModel.Primitives.Tests.csproj @@ -26,5 +26,10 @@ + + + \ No newline at end of file diff --git a/src/libraries/System.ComponentModel.TypeConverter/tests/System.ComponentModel.TypeConverter.Tests.csproj b/src/libraries/System.ComponentModel.TypeConverter/tests/System.ComponentModel.TypeConverter.Tests.csproj index 6abc8b4552ef5..0b536e692648a 100644 --- a/src/libraries/System.ComponentModel.TypeConverter/tests/System.ComponentModel.TypeConverter.Tests.csproj +++ b/src/libraries/System.ComponentModel.TypeConverter/tests/System.ComponentModel.TypeConverter.Tests.csproj @@ -166,6 +166,10 @@ + + diff --git a/src/libraries/System.Configuration.ConfigurationManager/tests/System.Configuration.ConfigurationManager.Tests.csproj b/src/libraries/System.Configuration.ConfigurationManager/tests/System.Configuration.ConfigurationManager.Tests.csproj index 8cece024e52e5..a4582dbd3584d 100644 --- a/src/libraries/System.Configuration.ConfigurationManager/tests/System.Configuration.ConfigurationManager.Tests.csproj +++ b/src/libraries/System.Configuration.ConfigurationManager/tests/System.Configuration.ConfigurationManager.Tests.csproj @@ -107,4 +107,10 @@ + + + + diff --git a/src/libraries/System.Data.Common/tests/System.Data.Common.Tests.csproj b/src/libraries/System.Data.Common/tests/System.Data.Common.Tests.csproj index ae85c66d7e8b5..dd1046a757ce3 100644 --- a/src/libraries/System.Data.Common/tests/System.Data.Common.Tests.csproj +++ b/src/libraries/System.Data.Common/tests/System.Data.Common.Tests.csproj @@ -118,6 +118,11 @@ Link="Common\System\Diagnostics\Tracing\TestEventListener.cs" /> + + + diff --git a/src/libraries/System.Net.Requests/tests/System.Net.Requests.Tests.csproj b/src/libraries/System.Net.Requests/tests/System.Net.Requests.Tests.csproj index fa0e6863cd8b9..4beb82617ee9a 100644 --- a/src/libraries/System.Net.Requests/tests/System.Net.Requests.Tests.csproj +++ b/src/libraries/System.Net.Requests/tests/System.Net.Requests.Tests.csproj @@ -53,5 +53,9 @@ + + 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 09e462b3c38e6..6fca6cd05e313 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 @@ -164,5 +164,9 @@ + + diff --git a/src/libraries/System.ObjectModel/tests/System.ObjectModel.Tests.csproj b/src/libraries/System.ObjectModel/tests/System.ObjectModel.Tests.csproj index f015015de4d3e..617a923fbdefd 100644 --- a/src/libraries/System.ObjectModel/tests/System.ObjectModel.Tests.csproj +++ b/src/libraries/System.ObjectModel/tests/System.ObjectModel.Tests.csproj @@ -42,5 +42,10 @@ + + + diff --git a/src/libraries/System.Reflection.Metadata/tests/System.Reflection.Metadata.Tests.csproj b/src/libraries/System.Reflection.Metadata/tests/System.Reflection.Metadata.Tests.csproj index a985caddfff1b..5eb2bf7446e71 100644 --- a/src/libraries/System.Reflection.Metadata/tests/System.Reflection.Metadata.Tests.csproj +++ b/src/libraries/System.Reflection.Metadata/tests/System.Reflection.Metadata.Tests.csproj @@ -152,6 +152,12 @@ + + + + diff --git a/src/libraries/System.Runtime.Serialization.Primitives/tests/System.Runtime.Serialization.Primitives.Tests.csproj b/src/libraries/System.Runtime.Serialization.Primitives/tests/System.Runtime.Serialization.Primitives.Tests.csproj index aa5368bbad535..bef1cc634e637 100644 --- a/src/libraries/System.Runtime.Serialization.Primitives/tests/System.Runtime.Serialization.Primitives.Tests.csproj +++ b/src/libraries/System.Runtime.Serialization.Primitives/tests/System.Runtime.Serialization.Primitives.Tests.csproj @@ -11,5 +11,10 @@ + + + \ No newline at end of file diff --git a/src/libraries/System.Runtime/tests/System.Resources.ResourceManager.Tests/System.Resources.ResourceManager.Tests.csproj b/src/libraries/System.Runtime/tests/System.Resources.ResourceManager.Tests/System.Resources.ResourceManager.Tests.csproj index 426654a590f7d..8b96b4c4aba10 100644 --- a/src/libraries/System.Runtime/tests/System.Resources.ResourceManager.Tests/System.Resources.ResourceManager.Tests.csproj +++ b/src/libraries/System.Runtime/tests/System.Resources.ResourceManager.Tests/System.Resources.ResourceManager.Tests.csproj @@ -61,6 +61,10 @@ + + + + diff --git a/src/libraries/System.Security.Cryptography/tests/System.Security.Cryptography.Tests.csproj b/src/libraries/System.Security.Cryptography/tests/System.Security.Cryptography.Tests.csproj index 0dea3f2b5f48b..13cda33052457 100644 --- a/src/libraries/System.Security.Cryptography/tests/System.Security.Cryptography.Tests.csproj +++ b/src/libraries/System.Security.Cryptography/tests/System.Security.Cryptography.Tests.csproj @@ -519,5 +519,9 @@ + + diff --git a/src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/System.Text.RegularExpressions.Tests.csproj b/src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/System.Text.RegularExpressions.Tests.csproj index dbab47f63d097..fa554e131a54f 100644 --- a/src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/System.Text.RegularExpressions.Tests.csproj +++ b/src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/System.Text.RegularExpressions.Tests.csproj @@ -85,6 +85,11 @@ SetTargetFramework="TargetFramework=netstandard2.0" OutputItemType="Analyzer" ReferenceOutputAssembly="true" /> + + + diff --git a/src/libraries/System.Threading.Channels/tests/System.Threading.Channels.Tests.csproj b/src/libraries/System.Threading.Channels/tests/System.Threading.Channels.Tests.csproj index 7d22b2afdee09..06e639f472a3c 100644 --- a/src/libraries/System.Threading.Channels/tests/System.Threading.Channels.Tests.csproj +++ b/src/libraries/System.Threading.Channels/tests/System.Threading.Channels.Tests.csproj @@ -17,6 +17,10 @@ + +