diff --git a/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs b/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs
index 2b3c1e4e00072a..67cde84c48389b 100644
--- a/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs
+++ b/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs
@@ -736,22 +736,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 494c88fba49313..962f3f02fca83b 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 69a3250dd15977..6b8a633698e6ef 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 d0e1a252098bd2..364fd2adff71df 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 d7674f24de7ebf..02a5a89db5c33c 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 e3d4829cdaba17..25a4803a5d14d5 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 83a763207a85c6..7c03f82de39349 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 a7415591d315b1..9d330b2beeb276 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 80d60eb2991f4b..21017a070becb4 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 6abc8b4552ef5a..0b536e692648a0 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 8cece024e52e56..a4582dbd3584d8 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 ae85c66d7e8b5f..dd1046a757ce34 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 a1574b47b66267..6c143ee85dd2b6 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 41577cfe2496cb..559ac8547084ac 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
@@ -165,5 +165,9 @@
+
+
diff --git a/src/libraries/System.ObjectModel/tests/System.ObjectModel.Tests.csproj b/src/libraries/System.ObjectModel/tests/System.ObjectModel.Tests.csproj
index f015015de4d3ed..617a923fbdefd5 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 a985caddfff1b6..5eb2bf7446e71b 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 aa5368bbad5350..bef1cc634e6373 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 426654a590f7d7..8b96b4c4aba10b 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 0dea3f2b5f48b3..13cda33052457e 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 dbab47f63d097c..fa554e131a54fb 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 7d22b2afdee09f..06e639f472a3ce 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 @@
+
+