Skip to content

Commit 14e5423

Browse files
github-actions[bot]ericstjadamsitniktmdsivanpovazan
authored
[release/9.0-rc2] [release/9.0] BinaryFormatter tests improvements (#107903)
* Remove package references from library tests (#106737) * Remove package references from library tests These tests should be referencing the product assemblies so that they test latest and not old bits. * Reference the OOB version of SRSF and make sure it's copied * 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<string>.Default is mapped to StringEqualityComparer, but serialized as GenericEqualityComparer<string> * Don't use WeakReferences in the round trip test, as the target may get freed in the meantime, fixes #104905 (#106967) * Enable more BinaryFormatter tests (#107408) * enable the BinaryFormatter tests in System.Runtime.Serialization.Formatters.Tests * add new test project, where the flag is disabled and it runs only 3 tests in total that ensure that * The SerializationGuard is no longer activated since BF was moved to the OOB package, the tests need to reflect that. * Disable binary formatter tests when DotNetBuildSourceOnly. (#107549) * [mono][tvos] Do not treat assembly.pdb/xml files as native files to bundle when AOTing on Helix (#107079) * Do not treat assembly.pdb/xml files as native files to bundle * Bundle satellite assemblies as well * [mono][ci] Include PDBs from runtime pack when building on Helix if required (#107348) --------- Co-authored-by: Eric StJohn <[email protected]> Co-authored-by: Adam Sitnik <[email protected]> Co-authored-by: Tom Deseyn <[email protected]> Co-authored-by: Ivan Povazan <[email protected]>
1 parent 7832c5d commit 14e5423

File tree

39 files changed

+223
-147
lines changed

39 files changed

+223
-147
lines changed

Directory.Build.props

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,8 @@
473473
<PropertyGroup Condition="'$(IsTestProject)' == 'true' or '$(IsTestSupportProject)' == 'true' or '$(IsTrimmingTestProject)' == 'true'">
474474
<!-- we need to re-enable BinaryFormatter within test projects since some tests exercise these code paths to ensure compat -->
475475
<EnableUnsafeBinaryFormatterSerialization>true</EnableUnsafeBinaryFormatterSerialization>
476+
<!-- For DotNetBuildSourceOnly, only the bundled BinaryFormatter is built which does not support serialization. -->
477+
<EnableUnsafeBinaryFormatterSerialization Condition="'$(DotNetBuildSourceOnly)' == 'true'">false</EnableUnsafeBinaryFormatterSerialization>
476478
<!-- don't warn on usage of BinaryFormatter or legacy serialization infrastructure from test projects -->
477479
<NoWarn>$(NoWarn);SYSLIB0011;SYSLIB0050;SYSLIB0051</NoWarn>
478480
<!-- don't warn about unnecessary trim warning suppressions. can be removed with preview 6. -->

eng/Versions.props

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,6 @@
163163
<MicrosoftDiaSymReaderVersion>2.0.0</MicrosoftDiaSymReaderVersion>
164164
<MicrosoftDiaSymReaderNativeVersion>17.10.0-beta1.24272.1</MicrosoftDiaSymReaderNativeVersion>
165165
<SystemCommandLineVersion>2.0.0-beta4.24324.3</SystemCommandLineVersion>
166-
<!-- This package provides working implementation of BinaryFormatter and is used only by test projects -->
167-
<SystemRuntimeSerializationFormattersVersion>9.0.0-preview.7.24327.2</SystemRuntimeSerializationFormattersVersion>
168166
<TraceEventVersion>3.1.7</TraceEventVersion>
169167
<NETStandardLibraryRefVersion>2.1.0</NETStandardLibraryRefVersion>
170168
<NetStandardLibraryVersion>2.0.3</NetStandardLibraryVersion>

eng/references.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
<ItemGroup>
4040
<ProjectReferenceWithConfiguration PrivateAssets="all"
4141
Private="false"
42-
Condition="$(NetCoreAppLibrary.Contains('%(Filename);'))" />
42+
Condition="$(NetCoreAppLibrary.Contains('%(Filename);')) and '%(ProjectReferenceWithConfiguration.Private)' == ''" />
4343
</ItemGroup>
4444
</Target>
4545

eng/testing/tests.ioslike.targets

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
<BundleFiles Condition="'%(AppleAssembliesToBundle._IsNative)' != 'true'"
7272
Include="@(AppleAssembliesToBundle)" TargetDir="publish\%(AppleAssembliesToBundle.RecursiveDir)" />
7373
<BundleFiles Include="@(AppleNativeFilesToBundle)" TargetDir="publish\%(AppleNativeFilesToBundle.RecursiveDir)" />
74+
<BundleFiles Include="@(_SatelliteAssemblies)" TargetDir="publish\%(_SatelliteAssemblies.RecursiveDir)" />
7475
<BundleFiles Include="$(RuntimeConfigFilePath)" TargetDir="publish" />
7576

7677
<BundleFiles Include="$(MonoProjectRoot)\msbuild\apple\data\*" TargetDir="publish" />
@@ -93,8 +94,7 @@
9394

9495
<ItemGroup Condition="'$(DebuggerSupport)' == 'true'">
9596
<!-- Add any pdb files, if available -->
96-
<_BundlePdbFiles Include="$([System.IO.Path]::ChangeExtension('%(AppleAssembliesToBundle.Identity)', '.pdb'))" />
97-
<BundleFiles Include="@(_BundlePdbFiles)" TargetDir="publish" Condition="Exists(%(_BundlePdbFiles.Identity))" />
97+
<BundleFiles Include="@(ApplePdbsToBundle)" TargetDir="publish" Condition="Exists(%(ApplePdbsToBundle.Identity))" />
9898
</ItemGroup>
9999

100100
<Copy SourceFiles="@(BundleFiles)" DestinationFolder="$(BundleDir)%(TargetDir)" />
@@ -213,7 +213,10 @@
213213
<_IsNative>false</_IsNative>
214214
</AppleAssembliesToBundle>
215215

216-
<AppleNativeFilesToBundle Include="$(PublishDir)\**\*.*" Exclude="$(PublishDir)\*.dll" />
216+
<ApplePdbsToBundle Include="$([System.IO.Path]::ChangeExtension('%(AppleAssembliesToBundle.Identity)', '.pdb'))" />
217+
<AppleXmlsToBundle Include="$([System.IO.Path]::ChangeExtension('%(AppleAssembliesToBundle.Identity)', '.xml'))" />
218+
219+
<AppleNativeFilesToBundle Include="$(PublishDir)\**\*.*" Exclude="@(AppleAssembliesToBundle);@(ApplePdbsToBundle);@(AppleXmlsToBundle);@(_SatelliteAssemblies)" />
217220
</ItemGroup>
218221
</Target>
219222

src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -736,22 +736,8 @@ private static bool DetermineBinaryFormatterSupport()
736736
return false;
737737
}
738738

739-
Assembly assembly = typeof(System.Runtime.Serialization.Formatters.Binary.BinaryFormatter).Assembly;
740-
AssemblyName name = assembly.GetName();
741-
Version assemblyVersion = name.Version;
742-
743-
bool isSupported = true;
744-
745-
// Version 8.1 is the version in the shared runtime (.NET 9+) that has the type disabled with no config.
746-
// Assembly versions beyond 8.1 are the fully functional version from NuGet.
747-
// Assembly versions before 8.1 probably won't be encountered, since that's the past.
748-
749-
if (assemblyVersion.Major == 8 && assemblyVersion.Minor == 1)
750-
{
751-
isSupported = false;
752-
}
753-
754-
return isSupported;
739+
return AppContext.TryGetSwitch("System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization", out bool isBinaryFormatterEnabled)
740+
&& isBinaryFormatterEnabled;
755741
}
756742
}
757743
}

src/libraries/Microsoft.Extensions.Hosting/tests/UnitTests/Microsoft.Extensions.Hosting.Unit.Tests.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,11 @@
1919
<ProjectReference Include="$(LibrariesProjectRoot)Microsoft.Extensions.Hosting\src\Microsoft.Extensions.Hosting.csproj" />
2020
</ItemGroup>
2121

22+
<ItemGroup Condition="'$(TargetFrameworkIdentifier)' != '.NETFramework'">
23+
<!-- Reference the `NetCoreAppMinimum` build which has a functional BinaryFormatter and force a private copy to ensure it's not excluded -->
24+
<ProjectReference Include="$(LibrariesProjectRoot)System.Runtime.Serialization.Formatters\src\System.Runtime.Serialization.Formatters.csproj"
25+
Private="true"
26+
SetTargetFramework="TargetFramework=$(NetCoreAppMinimum)" />
27+
</ItemGroup>
28+
2229
</Project>

src/libraries/System.Collections.NonGeneric/tests/System.Collections.NonGeneric.Tests.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,10 @@
4444
<Compile Include="CaseInsensitiveHashCodeProviderTests.cs" />
4545
<Compile Include="$(CommonTestPath)System\Collections\IEnumerable.NonGeneric.Serialization.Tests.cs"
4646
Link="Common\System\Collections\IEnumerable.NonGeneric.Serialization.Tests.cs" />
47+
48+
<!-- Reference the `NetCoreAppMinimum` build which has a functional BinaryFormatter and force a private copy to ensure it's not excluded -->
49+
<ProjectReference Include="$(LibrariesProjectRoot)System.Runtime.Serialization.Formatters\src\System.Runtime.Serialization.Formatters.csproj"
50+
Private="true"
51+
SetTargetFramework="TargetFramework=$(NetCoreAppMinimum)" />
4752
</ItemGroup>
4853
</Project>

src/libraries/System.Collections.Specialized/tests/System.Collections.Specialized.Tests.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,5 +75,10 @@
7575
<Compile Include="$(CommonTestPath)System\Collections\IEnumerable.NonGeneric.Serialization.Tests.cs"
7676
Link="Common\System\Collections\IEnumerable.NonGeneric.Serialization.Tests.cs" />
7777
<Compile Include="NameObjectCollectionBase\NameObjectCollectionBase.ConstructorTests.cs" />
78+
79+
<!-- Reference the `NetCoreAppMinimum` build which has a functional BinaryFormatter and force a private copy to ensure it's not excluded -->
80+
<ProjectReference Include="$(LibrariesProjectRoot)System.Runtime.Serialization.Formatters\src\System.Runtime.Serialization.Formatters.csproj"
81+
Private="true"
82+
SetTargetFramework="TargetFramework=$(NetCoreAppMinimum)" />
7883
</ItemGroup>
7984
</Project>

src/libraries/System.Collections/tests/Generic/Dictionary/Dictionary.Tests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,13 @@ private static void TestComparerSerialization<T>(IEqualityComparer<T> equalityCo
452452
s.Position = 0;
453453
dict = (Dictionary<T, T>)bf.Deserialize(s);
454454

455+
if (equalityComparer.Equals(EqualityComparer<string>.Default))
456+
{
457+
// EqualityComparer<string>.Default is mapped to StringEqualityComparer, but serialized as GenericEqualityComparer<string>
458+
Assert.Equal("System.Collections.Generic.GenericEqualityComparer`1[System.String]", dict.Comparer.GetType().ToString());
459+
return;
460+
}
461+
455462
if (internalTypeName == null)
456463
{
457464
Assert.IsType(equalityComparer.GetType(), dict.Comparer);

src/libraries/System.Collections/tests/Generic/HashSet/HashSet.Generic.Tests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -886,6 +886,13 @@ static void TestComparerSerialization<TCompared>(IEqualityComparer<TCompared> eq
886886
s.Position = 0;
887887
set = (HashSet<TCompared>)bf.Deserialize(s);
888888

889+
if (equalityComparer.Equals(EqualityComparer<string>.Default))
890+
{
891+
// EqualityComparer<string>.Default is mapped to StringEqualityComparer, but serialized as GenericEqualityComparer<string>
892+
Assert.Equal("System.Collections.Generic.GenericEqualityComparer`1[System.String]", set.Comparer.GetType().ToString());
893+
return;
894+
}
895+
889896
if (internalTypeName == null)
890897
{
891898
Assert.IsType(equalityComparer.GetType(), set.Comparer);

src/libraries/System.Collections/tests/System.Collections.Tests.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
<TestRuntime>true</TestRuntime>
55
<DebuggerSupport Condition="'$(DebuggerSupport)' == '' and ('$(TargetOS)' == 'browser' or '$(TargetOS)' == 'wasi')">true</DebuggerSupport>
66
</PropertyGroup>
7+
<ItemGroup>
8+
<!-- Reference the `NetCoreAppMinimum` build which has a functional BinaryFormatter and force a private copy to ensure it's not excluded -->
9+
<ProjectReference Include="$(LibrariesProjectRoot)System.Runtime.Serialization.Formatters\src\System.Runtime.Serialization.Formatters.csproj"
10+
Private="true"
11+
SetTargetFramework="TargetFramework=$(NetCoreAppMinimum)" />
12+
</ItemGroup>
713
<ItemGroup>
814
<RdXmlFile Include="default.rd.xml" />
915
</ItemGroup>

src/libraries/System.ComponentModel.Annotations/tests/System.ComponentModel.Annotations.Tests.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,10 @@
4848
<Compile Include="System\ComponentModel\DataAnnotations\ValidationResultTests.cs" />
4949
<Compile Include="System\ComponentModel\DataAnnotations\ValidatorTests.cs" />
5050
<Compile Include="System\ComponentModel\DataAnnotations\DeniedValuesAttributeTests.cs" />
51+
52+
<!-- Reference the `NetCoreAppMinimum` build which has a functional BinaryFormatter and force a private copy to ensure it's not excluded -->
53+
<ProjectReference Include="$(LibrariesProjectRoot)System.Runtime.Serialization.Formatters\src\System.Runtime.Serialization.Formatters.csproj"
54+
Private="true"
55+
SetTargetFramework="TargetFramework=$(NetCoreAppMinimum)" />
5156
</ItemGroup>
5257
</Project>

src/libraries/System.ComponentModel.Primitives/tests/System.ComponentModel.Primitives.Tests.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,10 @@
2626
<Compile Include="System\ComponentModel\ParenthesizePropertyNameAttributeTests.cs" />
2727
<Compile Include="System\ComponentModel\ReadOnlyAttributeTests.cs" />
2828
<Compile Include="System\ComponentModel\RefreshPropertiesAttributeTests.cs" />
29+
30+
<!-- Reference the `NetCoreAppMinimum` build which has a functional BinaryFormatter and force a private copy to ensure it's not excluded -->
31+
<ProjectReference Include="$(LibrariesProjectRoot)System.Runtime.Serialization.Formatters\src\System.Runtime.Serialization.Formatters.csproj"
32+
Private="true"
33+
SetTargetFramework="TargetFramework=$(NetCoreAppMinimum)" />
2934
</ItemGroup>
3035
</Project>

src/libraries/System.ComponentModel.TypeConverter/tests/System.ComponentModel.TypeConverter.Tests.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,10 @@
166166
<ItemGroup>
167167
<PackageReference Include="System.ComponentModel.TypeConverter.TestData" Version="$(SystemComponentModelTypeConverterTestDataVersion)" />
168168
<PackageReference Include="Moq" Version="$(MoqVersion)" />
169+
<!-- Reference the `NetCoreAppMinimum` build which has a functional BinaryFormatter and force a private copy to ensure it's not excluded -->
170+
<ProjectReference Include="$(LibrariesProjectRoot)System.Runtime.Serialization.Formatters\src\System.Runtime.Serialization.Formatters.csproj"
171+
Private="true"
172+
SetTargetFramework="TargetFramework=$(NetCoreAppMinimum)" />
169173
</ItemGroup>
170174
<ItemGroup>
171175
<EmbeddedResource Include="Resources\TestResx.resx">

src/libraries/System.Configuration.ConfigurationManager/tests/System.Configuration.ConfigurationManager.Tests.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,10 @@
107107
<!-- Manually reference the transitive dependency to make NuGet pick the package over the transitive project: https://github.com/NuGet/Home/issues/10368 -->
108108
<PackageReference Include="System.Security.Principal.Windows" Version="$(SystemSecurityPrincipalWindowsVersion)" PrivateAssets="all" />
109109
</ItemGroup>
110+
<ItemGroup Condition="'$(TargetFrameworkIdentifier)' != '.NETFramework'">
111+
<!-- Reference the `NetCoreAppMinimum` build which has a functional BinaryFormatter and force a private copy to ensure it's not excluded -->
112+
<ProjectReference Include="$(LibrariesProjectRoot)System.Runtime.Serialization.Formatters\src\System.Runtime.Serialization.Formatters.csproj"
113+
Private="true"
114+
SetTargetFramework="TargetFramework=$(NetCoreAppMinimum)" />
115+
</ItemGroup>
110116
</Project>

src/libraries/System.Data.Common/tests/System.Data.Common.Tests.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,11 @@
118118
Link="Common\System\Diagnostics\Tracing\TestEventListener.cs" />
119119
<Compile Include="$(CommonTestPath)System\Runtime\Serialization\Formatters\BinaryFormatterHelpers.cs"
120120
Link="Common\System\Runtime\Serialization\Formatters\BinaryFormatterHelpers.cs" />
121+
122+
<!-- Reference the `NetCoreAppMinimum` build which has a functional BinaryFormatter and force a private copy to ensure it's not excluded -->
123+
<ProjectReference Include="$(LibrariesProjectRoot)System.Runtime.Serialization.Formatters\src\System.Runtime.Serialization.Formatters.csproj"
124+
Private="true"
125+
SetTargetFramework="TargetFramework=$(NetCoreAppMinimum)" />
121126
</ItemGroup>
122127
<!-- S.D.SqlClient isn't live built anymore. -->
123128
<ItemGroup>

src/libraries/System.Formats.Nrbf/tests/System.Formats.Nrbf.Tests.csproj

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@
1515
</ItemGroup>
1616

1717
<ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework'">
18-
<PackageReference Include="System.Text.Json" Version="$(SystemTextJsonVersion)" />
18+
<ProjectReference Include="$(LibrariesProjectRoot)System.Text.Json\src\System.Text.Json.csproj" />
1919
</ItemGroup>
20-
20+
2121
<ItemGroup Condition="'$(TargetFrameworkIdentifier)' != '.NETFramework'">
22-
<PackageReference Include="System.Runtime.Serialization.Formatters" Version="$(SystemRuntimeSerializationFormattersVersion)" />
22+
<!-- Reference the `NetCoreAppMinimum` build which has a functional BinaryFormatter and force a private copy to ensure it's not excluded -->
23+
<ProjectReference Include="$(LibrariesProjectRoot)System.Runtime.Serialization.Formatters\src\System.Runtime.Serialization.Formatters.csproj"
24+
Private="true"
25+
SetTargetFramework="TargetFramework=$(NetCoreAppMinimum)" />
2326
</ItemGroup>
2427

2528
</Project>

src/libraries/System.Net.Http/tests/FunctionalTests/System.Net.Http.Functional.Tests.csproj

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -331,11 +331,9 @@
331331
<ItemGroup>
332332
<PackageReference Include="System.Net.TestData" Version="$(SystemNetTestDataVersion)" />
333333
<ProjectReference Include="$(LibrariesProjectRoot)System.DirectoryServices.Protocols\src\System.DirectoryServices.Protocols.csproj" />
334+
<ProjectReference Include="$(LibrariesProjectRoot)System.IO.Pipelines\src\System.IO.Pipelines.csproj" />
334335
</ItemGroup>
335336
<ItemGroup>
336337
<ProjectReference Include="$(CommonTestPath)StreamConformanceTests\StreamConformanceTests.csproj" />
337338
</ItemGroup>
338-
<ItemGroup>
339-
<PackageReference Include="System.IO.Pipelines" Version="7.0.0" />
340-
</ItemGroup>
341339
</Project>

src/libraries/System.Net.Requests/tests/System.Net.Requests.Tests.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,9 @@
5353
</ItemGroup>
5454
<ItemGroup>
5555
<PackageReference Include="System.Net.TestData" Version="$(SystemNetTestDataVersion)" />
56+
<!-- Reference the `NetCoreAppMinimum` build which has a functional BinaryFormatter and force a private copy to ensure it's not excluded -->
57+
<ProjectReference Include="$(LibrariesProjectRoot)System.Runtime.Serialization.Formatters\src\System.Runtime.Serialization.Formatters.csproj"
58+
Private="true"
59+
SetTargetFramework="TargetFramework=$(NetCoreAppMinimum)" />
5660
</ItemGroup>
5761
</Project>

src/libraries/System.Net.Security/tests/FunctionalTests/System.Net.Security.Tests.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,5 +165,9 @@
165165
</ItemGroup>
166166
<ItemGroup>
167167
<ProjectReference Include="$(CommonTestPath)StreamConformanceTests\StreamConformanceTests.csproj" />
168+
<!-- Reference the `NetCoreAppMinimum` build which has a functional BinaryFormatter and force a private copy to ensure it's not excluded -->
169+
<ProjectReference Include="$(LibrariesProjectRoot)System.Runtime.Serialization.Formatters\src\System.Runtime.Serialization.Formatters.csproj"
170+
Private="true"
171+
SetTargetFramework="TargetFramework=$(NetCoreAppMinimum)" />
168172
</ItemGroup>
169173
</Project>

src/libraries/System.Net.ServerSentEvents/tests/System.Net.ServerSentEvents.Tests.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@
1010

1111
<ItemGroup>
1212
<ProjectReference Include="..\src\System.Net.ServerSentEvents.csproj"/>
13+
<ProjectReference Include="$(LibrariesProjectRoot)System.Text.Json\gen\System.Text.Json.SourceGeneration.Roslyn4.4.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" SetTargetFramework="TargetFramework=netstandard2.0" />
1314
</ItemGroup>
1415

1516
<ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework'">
16-
<PackageReference Include="System.Text.Json" Version="$(SystemTextJsonVersion)" />
17+
<ProjectReference Include="$(LibrariesProjectRoot)System.Text.Json\src\System.Text.Json.csproj" />
1718
</ItemGroup>
1819

1920
</Project>

src/libraries/System.ObjectModel/tests/System.ObjectModel.Tests.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,10 @@
4242
<Compile Include="ReadOnlyObservableCollection\ReadOnlyObservableCollection_SerializationTests.cs" />
4343
<Compile Include="$(CommonTestPath)System\Runtime\Serialization\Formatters\BinaryFormatterHelpers.cs"
4444
Link="Common\System\Runtime\Serialization\Formatters\BinaryFormatterHelpers.cs" />
45+
46+
<!-- Reference the `NetCoreAppMinimum` build which has a functional BinaryFormatter and force a private copy to ensure it's not excluded -->
47+
<ProjectReference Include="$(LibrariesProjectRoot)System.Runtime.Serialization.Formatters\src\System.Runtime.Serialization.Formatters.csproj"
48+
Private="true"
49+
SetTargetFramework="TargetFramework=$(NetCoreAppMinimum)" />
4550
</ItemGroup>
4651
</Project>

src/libraries/System.Reflection.Metadata/tests/System.Reflection.Metadata.Tests.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,12 @@
152152
<ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework'">
153153
<PackageReference Include="System.ValueTuple" Version="$(SystemValueTupleVersion)" />
154154
</ItemGroup>
155+
<ItemGroup Condition="'$(TargetFrameworkIdentifier)' != '.NETFramework'">
156+
<!-- Reference the `NetCoreAppMinimum` build which has a functional BinaryFormatter and force a private copy to ensure it's not excluded -->
157+
<ProjectReference Include="$(LibrariesProjectRoot)System.Runtime.Serialization.Formatters\src\System.Runtime.Serialization.Formatters.csproj"
158+
Private="true"
159+
SetTargetFramework="TargetFramework=$(NetCoreAppMinimum)" />
160+
</ItemGroup>
155161

156162
<ItemGroup Condition="'$(TargetOS)' == 'browser'">
157163
<WasmFilesToIncludeFromPublishDir Include="$(AssemblyName).dll" />

src/libraries/System.Resources.Extensions/tests/BinaryFormatTests/FormattedObject/BasicObjectTests.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ public class BasicObjectTests : Common.BasicObjectTests<FormattedObjectSerialize
1414
[MemberData(nameof(SerializableObjects))]
1515
public void BasicObjectsRoundTripAndMatch(object value, TypeSerializableValue[] _)
1616
{
17+
if (value is WeakReference || (value.GetType().IsGenericType && value.GetType().GetGenericTypeDefinition() == typeof(WeakReference<>)))
18+
{
19+
// We can root the provided value, but we can't root the deserialized value:
20+
// GC can free the target of WeakReference after it gets deserialized,
21+
// but before it gets returned from BinaryFormatter.Deserialize.
22+
return;
23+
}
24+
1725
// We need to round trip through the BinaryFormatter as a few objects in tests remove
1826
// serialized data on deserialization.
1927
BinaryFormatter formatter = new();

src/libraries/System.Resources.Extensions/tests/BinaryFormatTests/System.Resources.Extensions.BinaryFormat.Tests.csproj

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,15 @@
3232
</EmbeddedResource>
3333
<EmbeddedResource Include="TestResources.resx" LogicalName="TestResources.resources" />
3434
</ItemGroup>
35-
35+
3636
<ItemGroup>
3737
<PackageReference Include="System.Drawing.Common.TestData" Version="$(SystemDrawingCommonTestDataVersion)" />
3838
<ProjectReference Include="..\..\src\System.Resources.Extensions.csproj" />
3939
<PackageReference Include="System.Drawing.Common" Version="$(SystemDrawingCommonVersion)" />
40-
<PackageReference Include="System.Runtime.Serialization.Formatters" Version="$(SystemRuntimeSerializationFormattersVersion)" />
40+
<!-- Reference the `NetCoreAppMinimum` build which has a functional BinaryFormatter and force a private copy to ensure it's not excluded -->
41+
<ProjectReference Include="$(LibrariesProjectRoot)System.Runtime.Serialization.Formatters\src\System.Runtime.Serialization.Formatters.csproj"
42+
Private="true"
43+
SetTargetFramework="TargetFramework=$(NetCoreAppMinimum)" />
4144
</ItemGroup>
4245

4346
<ItemGroup>

0 commit comments

Comments
 (0)