Skip to content

Commit c9acb0b

Browse files
Add a JsonSerializerIsReflectionEnabledByDefault property (#31626)
Adds a msbuild property that ties to the feature switch implemented in dotnet/runtime#83844. Default JsonSerializerIsReflectionEnabledByDefault in ASP.NET PublishAot apps to start the replacement of the ASP.NET JSON feature switch. Co-authored-by: Eric Erhardt <eric.erhardt@microsoft.com>
1 parent 57b3aa1 commit c9acb0b

File tree

5 files changed

+16
-5
lines changed

5 files changed

+16
-5
lines changed

src/Assets/TestProjects/KitchenSink/TestApp/TestApp.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
<CustomResourceTypesSupport>false</CustomResourceTypesSupport>
2727
<UseSystemResourceKeys>true</UseSystemResourceKeys>
2828
<DynamicCodeSupport>true</DynamicCodeSupport>
29+
<JsonSerializerIsReflectionEnabledByDefault>false</JsonSerializerIsReflectionEnabledByDefault>
2930
<BuiltInComInteropSupport>false</BuiltInComInteropSupport>
3031
<_EnableConsumingManagedCodeFromNativeHosting>false</_EnableConsumingManagedCodeFromNativeHosting>
3132
<EnableCppCLIHostActivation>false</EnableCppCLIHostActivation>

src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.targets

+10-5
Original file line numberDiff line numberDiff line change
@@ -558,16 +558,21 @@ Copyright (c) .NET Foundation. All rights reserved.
558558
Value="$(StartupHookSupport)"
559559
Trim="true" />
560560

561-
<RuntimeHostConfigurationOption Include="System.Threading.Thread.EnableAutoreleasePool"
562-
Condition="'$(AutoreleasePoolSupport)' != ''"
563-
Value="$(AutoreleasePoolSupport)"
564-
Trim="true" />
565-
566561
<RuntimeHostConfigurationOption Include="System.Text.Encoding.EnableUnsafeUTF7Encoding"
567562
Condition="'$(EnableUnsafeUTF7Encoding)' != ''"
568563
Value="$(EnableUnsafeUTF7Encoding)"
569564
Trim="true" />
570565

566+
<RuntimeHostConfigurationOption Include="System.Text.Json.JsonSerializer.IsReflectionEnabledByDefault"
567+
Condition="'$(JsonSerializerIsReflectionEnabledByDefault)' != ''"
568+
Value="$(JsonSerializerIsReflectionEnabledByDefault)"
569+
Trim="true" />
570+
571+
<RuntimeHostConfigurationOption Include="System.Threading.Thread.EnableAutoreleasePool"
572+
Condition="'$(AutoreleasePoolSupport)' != ''"
573+
Value="$(AutoreleasePoolSupport)"
574+
Trim="true" />
575+
571576
<RuntimeHostConfigurationOption Include="System.Threading.ThreadPool.MinThreads"
572577
Condition="'$(ThreadPoolMinThreads)' != ''"
573578
Value="$(ThreadPoolMinThreads)" />

src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAProjectWithAllFeatures.cs

+1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ public void It_publishes_the_project_correctly(string targetFramework, string []
9494
""System.Runtime.TieredPGO"": true,
9595
""System.StartupHookProvider.IsSupported"": false,
9696
""System.Text.Encoding.EnableUnsafeUTF7Encoding"": false,
97+
""System.Text.Json.JsonSerializer.IsReflectionEnabledByDefault"": false,
9798
""System.Threading.Thread.EnableAutoreleasePool"": false,
9899
""System.Threading.ThreadPool.MinThreads"": 2,
99100
""System.Threading.ThreadPool.MaxThreads"": 9,

src/Tests/Microsoft.NET.Sdk.Web.Tests/PublishTests.cs

+3
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ public void TrimmingOptions_Are_Defaulted_Correctly_On_Trimmed_Apps(string targe
4949

5050
configProperties["Microsoft.AspNetCore.EnsureJsonTrimmability"].GetValue<bool>()
5151
.Should().BeTrue();
52+
configProperties["System.Text.Json.JsonSerializer.IsReflectionEnabledByDefault"].GetValue<bool>()
53+
.Should().BeFalse();
5254
}
5355

5456
[Theory]
@@ -81,6 +83,7 @@ public void TrimmingOptions_Are_Defaulted_Correctly_On_Aot_Apps(string targetFra
8183
var responseFileContents = File.ReadLines(responseFile);
8284

8385
responseFileContents.Should().Contain("--feature:Microsoft.AspNetCore.EnsureJsonTrimmability=true");
86+
responseFileContents.Should().Contain("--feature:System.Text.Json.JsonSerializer.IsReflectionEnabledByDefault=false");
8487
File.Exists(Path.Combine(outputDirectory, "web.config")).Should().BeFalse();
8588
}
8689

src/WebSdk/ProjectSystem/Targets/Microsoft.NET.Sdk.Web.ProjectSystem.targets

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ Copyright (c) .NET Foundation. All rights reserved.
4949
<PropertyGroup Condition="'$(PublishTrimmed)' == 'true' Or '$(PublishAot)' == 'true'">
5050
<!-- Runtime feature defaults to trim unnecessary code -->
5151
<EnsureAspNetCoreJsonTrimmability Condition="'$(EnsureAspNetCoreJsonTrimmability)' == ''">true</EnsureAspNetCoreJsonTrimmability>
52+
<JsonSerializerIsReflectionEnabledByDefault Condition="'$(JsonSerializerIsReflectionEnabledByDefault)' == ''">false</JsonSerializerIsReflectionEnabledByDefault>
5253
</PropertyGroup>
5354

5455
<!--

0 commit comments

Comments
 (0)