diff --git a/Directory.Build.props b/Directory.Build.props index e887d066f5c38..13cdf30eb7a92 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -473,6 +473,8 @@ true + + false $(NoWarn);SYSLIB0011;SYSLIB0050;SYSLIB0051 diff --git a/eng/Versions.props b/eng/Versions.props index 6ea06ef71c116..a181901cab6cc 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -163,8 +163,6 @@ 2.0.0 17.10.0-beta1.24272.1 2.0.0-beta4.24324.3 - - 9.0.0-preview.7.24327.2 3.1.7 2.1.0 2.0.3 diff --git a/eng/references.targets b/eng/references.targets index d54606f17ab79..2b0035d3054a1 100644 --- a/eng/references.targets +++ b/eng/references.targets @@ -39,7 +39,7 @@ + Condition="$(NetCoreAppLibrary.Contains('%(Filename);')) and '%(ProjectReferenceWithConfiguration.Private)' == ''" /> diff --git a/eng/testing/tests.ioslike.targets b/eng/testing/tests.ioslike.targets index dde49575d7ae4..a59cce6c49aee 100644 --- a/eng/testing/tests.ioslike.targets +++ b/eng/testing/tests.ioslike.targets @@ -71,6 +71,7 @@ + @@ -93,8 +94,7 @@ - <_BundlePdbFiles Include="$([System.IO.Path]::ChangeExtension('%(AppleAssembliesToBundle.Identity)', '.pdb'))" /> - + @@ -213,7 +213,10 @@ <_IsNative>false - + + + + diff --git a/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs b/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs index 2b3c1e4e00072..67cde84c48389 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 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 c6d33e3a5fe59..b8272e1852bbb 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.Formats.Nrbf/tests/System.Formats.Nrbf.Tests.csproj b/src/libraries/System.Formats.Nrbf/tests/System.Formats.Nrbf.Tests.csproj index 513d152362e24..a9da043b5ecd5 100644 --- a/src/libraries/System.Formats.Nrbf/tests/System.Formats.Nrbf.Tests.csproj +++ b/src/libraries/System.Formats.Nrbf/tests/System.Formats.Nrbf.Tests.csproj @@ -15,11 +15,14 @@ - + - + - + + diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/System.Net.Http.Functional.Tests.csproj b/src/libraries/System.Net.Http/tests/FunctionalTests/System.Net.Http.Functional.Tests.csproj index 7ca899166bc40..28dd6768061a0 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/System.Net.Http.Functional.Tests.csproj +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/System.Net.Http.Functional.Tests.csproj @@ -331,11 +331,9 @@ + - - - 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 a1574b47b6626..6c143ee85dd2b 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 41577cfe2496c..559ac8547084a 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.Net.ServerSentEvents/tests/System.Net.ServerSentEvents.Tests.csproj b/src/libraries/System.Net.ServerSentEvents/tests/System.Net.ServerSentEvents.Tests.csproj index e2b3d73610d48..ca685119d3dab 100644 --- a/src/libraries/System.Net.ServerSentEvents/tests/System.Net.ServerSentEvents.Tests.csproj +++ b/src/libraries/System.Net.ServerSentEvents/tests/System.Net.ServerSentEvents.Tests.csproj @@ -10,10 +10,11 @@ + - + 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.Resources.Extensions/tests/BinaryFormatTests/FormattedObject/BasicObjectTests.cs b/src/libraries/System.Resources.Extensions/tests/BinaryFormatTests/FormattedObject/BasicObjectTests.cs index b316a3e32b502..fd5fdc9b8c01a 100644 --- a/src/libraries/System.Resources.Extensions/tests/BinaryFormatTests/FormattedObject/BasicObjectTests.cs +++ b/src/libraries/System.Resources.Extensions/tests/BinaryFormatTests/FormattedObject/BasicObjectTests.cs @@ -14,6 +14,14 @@ public class BasicObjectTests : Common.BasicObjectTests))) + { + // We can root the provided value, but we can't root the deserialized value: + // GC can free the target of WeakReference after it gets deserialized, + // but before it gets returned from BinaryFormatter.Deserialize. + return; + } + // We need to round trip through the BinaryFormatter as a few objects in tests remove // serialized data on deserialization. BinaryFormatter formatter = new(); diff --git a/src/libraries/System.Resources.Extensions/tests/BinaryFormatTests/System.Resources.Extensions.BinaryFormat.Tests.csproj b/src/libraries/System.Resources.Extensions/tests/BinaryFormatTests/System.Resources.Extensions.BinaryFormat.Tests.csproj index 668bb0c91eeed..b3d238081a2ec 100644 --- a/src/libraries/System.Resources.Extensions/tests/BinaryFormatTests/System.Resources.Extensions.BinaryFormat.Tests.csproj +++ b/src/libraries/System.Resources.Extensions/tests/BinaryFormatTests/System.Resources.Extensions.BinaryFormat.Tests.csproj @@ -32,12 +32,15 @@ - + - + + diff --git a/src/libraries/System.Resources.Extensions/tests/CompatTests/System.Resources.Extensions.Compat.Tests.csproj b/src/libraries/System.Resources.Extensions/tests/CompatTests/System.Resources.Extensions.Compat.Tests.csproj index e56833eb8b284..6f7bc5fd56755 100644 --- a/src/libraries/System.Resources.Extensions/tests/CompatTests/System.Resources.Extensions.Compat.Tests.csproj +++ b/src/libraries/System.Resources.Extensions/tests/CompatTests/System.Resources.Extensions.Compat.Tests.csproj @@ -18,16 +18,16 @@ - - + + + - - - diff --git a/src/libraries/System.Resources.Extensions/tests/System.Resources.Extensions.Tests.csproj b/src/libraries/System.Resources.Extensions/tests/System.Resources.Extensions.Tests.csproj index d9fb191bb6930..4ef8e28d3d654 100644 --- a/src/libraries/System.Resources.Extensions/tests/System.Resources.Extensions.Tests.csproj +++ b/src/libraries/System.Resources.Extensions/tests/System.Resources.Extensions.Tests.csproj @@ -21,7 +21,10 @@ - + + diff --git a/src/libraries/System.Runtime.Serialization.Formatters/System.Runtime.Serialization.Formatters.sln b/src/libraries/System.Runtime.Serialization.Formatters/System.Runtime.Serialization.Formatters.sln index 868141ca7b35a..1ba7307c7f880 100644 --- a/src/libraries/System.Runtime.Serialization.Formatters/System.Runtime.Serialization.Formatters.sln +++ b/src/libraries/System.Runtime.Serialization.Formatters/System.Runtime.Serialization.Formatters.sln @@ -149,6 +149,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ref", "tools\ref", "{CDD725 EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tools", "tools", "{21D78340-7F96-4519-983F-529077A11AE1}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Runtime.Serialization.Formatters.Disabled.Tests", "tests\Disabled\System.Runtime.Serialization.Formatters.Disabled.Tests.csproj", "{0C8ADEFB-33FB-4785-A828-93377745B2BA}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -1584,6 +1586,36 @@ Global {5149AC24-C1A7-4A4C-BE83-FF3037B99E4C}.Checked|arm64.ActiveCfg = Debug|Any CPU {5149AC24-C1A7-4A4C-BE83-FF3037B99E4C}.Checked|x64.ActiveCfg = Debug|Any CPU {5149AC24-C1A7-4A4C-BE83-FF3037B99E4C}.Checked|x86.ActiveCfg = Debug|Any CPU + {0C8ADEFB-33FB-4785-A828-93377745B2BA}.Checked|Any CPU.ActiveCfg = Debug|Any CPU + {0C8ADEFB-33FB-4785-A828-93377745B2BA}.Checked|Any CPU.Build.0 = Debug|Any CPU + {0C8ADEFB-33FB-4785-A828-93377745B2BA}.Checked|arm.ActiveCfg = Debug|Any CPU + {0C8ADEFB-33FB-4785-A828-93377745B2BA}.Checked|arm.Build.0 = Debug|Any CPU + {0C8ADEFB-33FB-4785-A828-93377745B2BA}.Checked|arm64.ActiveCfg = Debug|Any CPU + {0C8ADEFB-33FB-4785-A828-93377745B2BA}.Checked|arm64.Build.0 = Debug|Any CPU + {0C8ADEFB-33FB-4785-A828-93377745B2BA}.Checked|x64.ActiveCfg = Debug|Any CPU + {0C8ADEFB-33FB-4785-A828-93377745B2BA}.Checked|x64.Build.0 = Debug|Any CPU + {0C8ADEFB-33FB-4785-A828-93377745B2BA}.Checked|x86.ActiveCfg = Debug|Any CPU + {0C8ADEFB-33FB-4785-A828-93377745B2BA}.Checked|x86.Build.0 = Debug|Any CPU + {0C8ADEFB-33FB-4785-A828-93377745B2BA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0C8ADEFB-33FB-4785-A828-93377745B2BA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0C8ADEFB-33FB-4785-A828-93377745B2BA}.Debug|arm.ActiveCfg = Debug|Any CPU + {0C8ADEFB-33FB-4785-A828-93377745B2BA}.Debug|arm.Build.0 = Debug|Any CPU + {0C8ADEFB-33FB-4785-A828-93377745B2BA}.Debug|arm64.ActiveCfg = Debug|Any CPU + {0C8ADEFB-33FB-4785-A828-93377745B2BA}.Debug|arm64.Build.0 = Debug|Any CPU + {0C8ADEFB-33FB-4785-A828-93377745B2BA}.Debug|x64.ActiveCfg = Debug|Any CPU + {0C8ADEFB-33FB-4785-A828-93377745B2BA}.Debug|x64.Build.0 = Debug|Any CPU + {0C8ADEFB-33FB-4785-A828-93377745B2BA}.Debug|x86.ActiveCfg = Debug|Any CPU + {0C8ADEFB-33FB-4785-A828-93377745B2BA}.Debug|x86.Build.0 = Debug|Any CPU + {0C8ADEFB-33FB-4785-A828-93377745B2BA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0C8ADEFB-33FB-4785-A828-93377745B2BA}.Release|Any CPU.Build.0 = Release|Any CPU + {0C8ADEFB-33FB-4785-A828-93377745B2BA}.Release|arm.ActiveCfg = Release|Any CPU + {0C8ADEFB-33FB-4785-A828-93377745B2BA}.Release|arm.Build.0 = Release|Any CPU + {0C8ADEFB-33FB-4785-A828-93377745B2BA}.Release|arm64.ActiveCfg = Release|Any CPU + {0C8ADEFB-33FB-4785-A828-93377745B2BA}.Release|arm64.Build.0 = Release|Any CPU + {0C8ADEFB-33FB-4785-A828-93377745B2BA}.Release|x64.ActiveCfg = Release|Any CPU + {0C8ADEFB-33FB-4785-A828-93377745B2BA}.Release|x64.Build.0 = Release|Any CPU + {0C8ADEFB-33FB-4785-A828-93377745B2BA}.Release|x86.ActiveCfg = Release|Any CPU + {0C8ADEFB-33FB-4785-A828-93377745B2BA}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -1659,6 +1691,7 @@ Global {E8705420-F755-4CBA-970D-B745F59F9780} = {21D78340-7F96-4519-983F-529077A11AE1} {5149AC24-C1A7-4A4C-BE83-FF3037B99E4C} = {CDD72541-F0ED-41FA-9C9A-5D774CEB22E4} {CDD72541-F0ED-41FA-9C9A-5D774CEB22E4} = {21D78340-7F96-4519-983F-529077A11AE1} + {0C8ADEFB-33FB-4785-A828-93377745B2BA} = {F8CB1B1F-F935-4ECE-B3C2-CF62B5654BF2} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {158060A0-BFF9-48E6-90A9-93F52FEB5D3B} diff --git a/src/libraries/System.Runtime.Serialization.Formatters/tests/DisableBitTests.cs b/src/libraries/System.Runtime.Serialization.Formatters/tests/Disabled/DisableBitTests.cs similarity index 100% rename from src/libraries/System.Runtime.Serialization.Formatters/tests/DisableBitTests.cs rename to src/libraries/System.Runtime.Serialization.Formatters/tests/Disabled/DisableBitTests.cs diff --git a/src/libraries/System.Runtime.Serialization.Formatters/tests/Disabled/System.Runtime.Serialization.Formatters.Disabled.Tests.csproj b/src/libraries/System.Runtime.Serialization.Formatters/tests/Disabled/System.Runtime.Serialization.Formatters.Disabled.Tests.csproj new file mode 100644 index 0000000000000..8ea7a29a3930b --- /dev/null +++ b/src/libraries/System.Runtime.Serialization.Formatters/tests/Disabled/System.Runtime.Serialization.Formatters.Disabled.Tests.csproj @@ -0,0 +1,23 @@ + + + true + true + $(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-freebsd;$(NetCoreAppCurrent)-illumos;$(NetCoreAppCurrent)-solaris;$(NetCoreAppCurrent)-haiku;$(NetCoreAppCurrent)-linux;$(NetCoreAppCurrent)-osx;$(NetCoreAppCurrent)-ios;$(NetCoreAppCurrent)-tvos + + + + + + + + + + + + + diff --git a/src/libraries/System.Runtime.Serialization.Formatters/tests/SerializationGuardTests.cs b/src/libraries/System.Runtime.Serialization.Formatters/tests/SerializationGuardTests.cs index 3805070b47d8e..444e0cc2f3856 100644 --- a/src/libraries/System.Runtime.Serialization.Formatters/tests/SerializationGuardTests.cs +++ b/src/libraries/System.Runtime.Serialization.Formatters/tests/SerializationGuardTests.cs @@ -1,125 +1,40 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using System; -using System.Diagnostics; using System.IO; -using System.Reflection; using System.Runtime.Serialization.Formatters.Binary; -using System.Threading; -using System.Threading.Tasks; using Xunit; namespace System.Runtime.Serialization.Formatters.Tests { + // When BinaryFormatter was built-in to the platform we used to activate SerializationGuard in ObjectReader.Deserialize, + // but now that it has moved to an OOB offering it no longer does. [ConditionalClass(typeof(TestConfiguration), nameof(TestConfiguration.IsBinaryFormatterEnabled))] public static class SerializationGuardTests { [Fact] - public static void BlockAssemblyLoads() - { - TryPayload(new AssemblyLoader()); - } - - [Fact] - public static void BlockProcessStarts() - { - TryPayload(new ProcessStarter()); - } - - [Fact] - public static void BlockFileWrites() - { - TryPayload(new FileWriter()); - } - - [Fact] - public static void BlockAsyncDodging() - { - TryPayload(new AsyncDodger()); - } - - private static void TryPayload(object payload) + public static void IsNoLongerActivated() { MemoryStream ms = new MemoryStream(); BinaryFormatter writer = new BinaryFormatter(); - writer.Serialize(ms, payload); + writer.Serialize(ms, new ThrowIfDeserializationInProgress()); ms.Position = 0; BinaryFormatter reader = new BinaryFormatter(); - SerializationException se = Assert.Throws(() => reader.Deserialize(ms)); - Assert.IsAssignableFrom(se.InnerException); - } - } - - [Serializable] - internal class AssemblyLoader : ISerializable - { - public AssemblyLoader() { } - - public AssemblyLoader(SerializationInfo info, StreamingContext context) - { - Assembly.Load(new byte[1000]); - } - - public void GetObjectData(SerializationInfo info, StreamingContext context) - { + Assert.NotNull(reader.Deserialize(ms)); } } [Serializable] - internal class ProcessStarter : ISerializable + internal class ThrowIfDeserializationInProgress : ISerializable { - public ProcessStarter() { } - - private ProcessStarter(SerializationInfo info, StreamingContext context) - { - Process.Start("calc.exe"); - } + private static int s_cachedSerializationSwitch; - public void GetObjectData(SerializationInfo info, StreamingContext context) - { - } - } - - [Serializable] - internal class FileWriter : ISerializable - { - public FileWriter() { } - - private FileWriter(SerializationInfo info, StreamingContext context) - { - string tempPath = Path.GetTempFileName(); - File.WriteAllText(tempPath, "This better not be written..."); - throw new UnreachableException("Unreachable code (SerializationGuard should have kicked in)"); - } - - public void GetObjectData(SerializationInfo info, StreamingContext context) - { - } - } - - [Serializable] - internal class AsyncDodger : ISerializable - { - public AsyncDodger() { } - - private AsyncDodger(SerializationInfo info, StreamingContext context) - { - try - { - Task t = Task.Factory.StartNew(LoadAssemblyOnBackgroundThread, TaskCreationOptions.LongRunning); - t.Wait(); - } - catch (AggregateException ex) - { - throw ex.InnerException; - } - } + public ThrowIfDeserializationInProgress() { } - private void LoadAssemblyOnBackgroundThread() + private ThrowIfDeserializationInProgress(SerializationInfo info, StreamingContext context) { - Assembly.Load(new byte[1000]); + SerializationGuard.ThrowIfDeserializationInProgress("AllowProcessCreation", ref s_cachedSerializationSwitch); } public void GetObjectData(SerializationInfo info, StreamingContext context) diff --git a/src/libraries/System.Runtime.Serialization.Formatters/tests/System.Runtime.Serialization.Formatters.Tests.csproj b/src/libraries/System.Runtime.Serialization.Formatters/tests/System.Runtime.Serialization.Formatters.Tests.csproj index 03df94a257abd..96a0f784a2372 100644 --- a/src/libraries/System.Runtime.Serialization.Formatters/tests/System.Runtime.Serialization.Formatters.Tests.csproj +++ b/src/libraries/System.Runtime.Serialization.Formatters/tests/System.Runtime.Serialization.Formatters.Tests.csproj @@ -7,7 +7,6 @@ - @@ -36,6 +35,8 @@ + @@ -48,8 +49,11 @@ - + + @@ -65,15 +69,4 @@ - - - - - - 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 @@ + + diff --git a/src/mono/msbuild/apple/data/ProxyProjectForAOTOnHelix.proj b/src/mono/msbuild/apple/data/ProxyProjectForAOTOnHelix.proj index 0230c7d10d3a5..2847f567f469a 100644 --- a/src/mono/msbuild/apple/data/ProxyProjectForAOTOnHelix.proj +++ b/src/mono/msbuild/apple/data/ProxyProjectForAOTOnHelix.proj @@ -109,8 +109,8 @@ Condition="'$(UsePortableRuntimePack)' == 'true'"> - <_RuntimePackFiles Condition="%(_AppleUsedRuntimePackFiles.Extension) == '.dll' and %(_AppleUsedRuntimePackFiles.FileName) != 'System.Private.CoreLib'" Include="@(_AppleUsedRuntimePackFiles->'$(MicrosoftNetCoreAppRuntimePackLibDir)%(FileName)%(Extension)')" /> - <_RuntimePackFiles Condition="%(_AppleUsedRuntimePackFiles.Extension) != '.dll' or %(_AppleUsedRuntimePackFiles.FileName) == 'System.Private.CoreLib'" Include="@(_AppleUsedRuntimePackFiles->'$(MicrosoftNetCoreAppRuntimePackNativeDir)%(FileName)%(Extension)')" /> + <_RuntimePackFiles Condition="(%(_AppleUsedRuntimePackFiles.Extension) == '.dll' or %(_AppleUsedRuntimePackFiles.Extension) == '.pdb') and %(_AppleUsedRuntimePackFiles.FileName) != 'System.Private.CoreLib'" Include="@(_AppleUsedRuntimePackFiles->'$(MicrosoftNetCoreAppRuntimePackLibDir)%(FileName)%(Extension)')" /> + <_RuntimePackFiles Condition="(%(_AppleUsedRuntimePackFiles.Extension) != '.dll' and %(_AppleUsedRuntimePackFiles.Extension) != '.pdb') or %(_AppleUsedRuntimePackFiles.FileName) == 'System.Private.CoreLib'" Include="@(_AppleUsedRuntimePackFiles->'$(MicrosoftNetCoreAppRuntimePackNativeDir)%(FileName)%(Extension)')" />