Skip to content

Commit

Permalink
Add a JsonSerializerIsReflectionEnabledByDefault property (#31626)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
eiriktsarpalis and eerhardt authored Apr 14, 2023
1 parent 57b3aa1 commit c9acb0b
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/Assets/TestProjects/KitchenSink/TestApp/TestApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<CustomResourceTypesSupport>false</CustomResourceTypesSupport>
<UseSystemResourceKeys>true</UseSystemResourceKeys>
<DynamicCodeSupport>true</DynamicCodeSupport>
<JsonSerializerIsReflectionEnabledByDefault>false</JsonSerializerIsReflectionEnabledByDefault>
<BuiltInComInteropSupport>false</BuiltInComInteropSupport>
<_EnableConsumingManagedCodeFromNativeHosting>false</_EnableConsumingManagedCodeFromNativeHosting>
<EnableCppCLIHostActivation>false</EnableCppCLIHostActivation>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -558,16 +558,21 @@ Copyright (c) .NET Foundation. All rights reserved.
Value="$(StartupHookSupport)"
Trim="true" />

<RuntimeHostConfigurationOption Include="System.Threading.Thread.EnableAutoreleasePool"
Condition="'$(AutoreleasePoolSupport)' != ''"
Value="$(AutoreleasePoolSupport)"
Trim="true" />

<RuntimeHostConfigurationOption Include="System.Text.Encoding.EnableUnsafeUTF7Encoding"
Condition="'$(EnableUnsafeUTF7Encoding)' != ''"
Value="$(EnableUnsafeUTF7Encoding)"
Trim="true" />

<RuntimeHostConfigurationOption Include="System.Text.Json.JsonSerializer.IsReflectionEnabledByDefault"
Condition="'$(JsonSerializerIsReflectionEnabledByDefault)' != ''"
Value="$(JsonSerializerIsReflectionEnabledByDefault)"
Trim="true" />

<RuntimeHostConfigurationOption Include="System.Threading.Thread.EnableAutoreleasePool"
Condition="'$(AutoreleasePoolSupport)' != ''"
Value="$(AutoreleasePoolSupport)"
Trim="true" />

<RuntimeHostConfigurationOption Include="System.Threading.ThreadPool.MinThreads"
Condition="'$(ThreadPoolMinThreads)' != ''"
Value="$(ThreadPoolMinThreads)" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public void It_publishes_the_project_correctly(string targetFramework, string []
""System.Runtime.TieredPGO"": true,
""System.StartupHookProvider.IsSupported"": false,
""System.Text.Encoding.EnableUnsafeUTF7Encoding"": false,
""System.Text.Json.JsonSerializer.IsReflectionEnabledByDefault"": false,
""System.Threading.Thread.EnableAutoreleasePool"": false,
""System.Threading.ThreadPool.MinThreads"": 2,
""System.Threading.ThreadPool.MaxThreads"": 9,
Expand Down
3 changes: 3 additions & 0 deletions src/Tests/Microsoft.NET.Sdk.Web.Tests/PublishTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public void TrimmingOptions_Are_Defaulted_Correctly_On_Trimmed_Apps(string targe

configProperties["Microsoft.AspNetCore.EnsureJsonTrimmability"].GetValue<bool>()
.Should().BeTrue();
configProperties["System.Text.Json.JsonSerializer.IsReflectionEnabledByDefault"].GetValue<bool>()
.Should().BeFalse();
}

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Copyright (c) .NET Foundation. All rights reserved.
<PropertyGroup Condition="'$(PublishTrimmed)' == 'true' Or '$(PublishAot)' == 'true'">
<!-- Runtime feature defaults to trim unnecessary code -->
<EnsureAspNetCoreJsonTrimmability Condition="'$(EnsureAspNetCoreJsonTrimmability)' == ''">true</EnsureAspNetCoreJsonTrimmability>
<JsonSerializerIsReflectionEnabledByDefault Condition="'$(JsonSerializerIsReflectionEnabledByDefault)' == ''">false</JsonSerializerIsReflectionEnabledByDefault>
</PropertyGroup>

<!--
Expand Down

0 comments on commit c9acb0b

Please sign in to comment.