Skip to content

Add tests for disabling JsonSerializer.IsReflectionEnabledByDefault on PublishTrimmed=true #33757

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -970,6 +970,12 @@ public void TrimmingOptions_are_defaulted_correctly_on_trimmed_apps(string targe
.Should().BeFalse();
configProperties["System.Threading.Thread.EnableAutoreleasePool"].Value<bool>()
.Should().BeFalse();

if (parsedVersion.Major >= 8)
{
configProperties["System.Text.Json.JsonSerializer.IsReflectionEnabledByDefault"].Value<bool>()
.Should().BeFalse();
}
}
else
{
Expand Down Expand Up @@ -1698,8 +1704,12 @@ public void Build_respects_PublishTrimmed_property(string targetFramework)

// runtimeconfig has trim settings
JObject runtimeConfig = JObject.Parse(File.ReadAllText(runtimeConfigPath));
JToken startupHookSupport = runtimeConfig["runtimeOptions"]["configProperties"]["System.StartupHookProvider.IsSupported"];
startupHookSupport.Value<bool>().Should().BeFalse();
JToken configProperties = runtimeConfig["runtimeOptions"]["configProperties"];

configProperties["System.StartupHookProvider.IsSupported"].Value<bool>().Should().BeFalse();

// Build with PublishTrimmed enabled should disable System.Text.Json reflection
configProperties["System.Text.Json.JsonSerializer.IsReflectionEnabledByDefault"].Value<bool>().Should().BeFalse();

// just setting PublishTrimmed doesn't inject the IsTrimmable attribute
AssemblyInfo.Get(assemblyPath).ContainsKey("AssemblyMetadataAttribute").Should().BeFalse();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@ Copyright (c) .NET Foundation. All rights reserved.
<EnableUnsafeBinaryFormatterSerialization Condition="'$(EnableUnsafeBinaryFormatterSerialization)' == ''">false</EnableUnsafeBinaryFormatterSerialization>
</PropertyGroup>

<!-- Default settings for trimmed and aot'd apps. -->
<PropertyGroup Condition="'$(PublishTrimmed)' == 'true' Or '$(PublishAot)' == 'true'">
<JsonSerializerIsReflectionEnabledByDefault Condition="'$(JsonSerializerIsReflectionEnabledByDefault)' == ''">false</JsonSerializerIsReflectionEnabledByDefault>
</PropertyGroup>

<!-- Default settings for aot'd apps. -->
<PropertyGroup Condition="'$(PublishAot)' == 'true'">
<!-- Enable the built-in source generators. -->
Expand Down