-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Disable JsonSerializer.IsReflectionEnabledByDefault on PublishTrimmed=true
#84378
Comments
Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis Issue DetailsHave we decided we want this to be defaulted to For the ASP.NET feature switch, we had it for both. But I'm a little concerned about making the switch for We don't need to block this PR on the decision. For ASP.NET, we can just switch our SDK to change Originally posted by @eerhardt in #83844 (comment)
|
FYI @Redth @PureWeen @jonathanpeppers @SteveSandersonMS @javiercn @marek-safar @lewing @SamMonoRT @steveisok - (please also tag anyone else you'd think would be interested from a MAUI or Blazor WASM stand point). We are considering disabling Reflection in System.Text.Json by default in a |
I assume this would also affect WASDK (WinUI 3) apps? |
Yes, if you set |
Not sure if this point has already been raised (probably?), but are there concerns about code potentially breaking due to this change and surprising developers? Is the assumption that if you enable trimming you'd already get all trimming warnings anyway, and in order to fix those you would already have to switch to code paths that are guaranteed to be safe when this flag is disabled? As in, just so that people won't encounter unexpected issues that only come up in published builds and not in normal ones? 🤔 I guess what I'm trying to say is that for people wanting to publish their apps with trimming, my expectations would be that this flag should always be disabled to ensure they get a consistent behavior even for normal F5 builds. Is that just not doable and relying on trimming warnings alone is sufficient? |
See also the discussion here dotnet/sdk#31626 (comment), which explains more of the reasoning why we should turn off Reflection in System.Text.Json when |
What project types needs the setting on vs off? If these need it on: wasm, iOS + 3 other Apples, Android. Do only the platforms running Mono need to keep it on? |
Projects that use the fragile
This is unrelated to the runtime flavor used. |
That’s a good idea. I would go with the policy based on TrimMode == full though. So when PublishTrimmed == true (which it is for PublishAot as well) && TrimMode == full -> default JsonSerializer.IsReflectionEnabledByDefault = false. |
Why would it be better option? |
I guess it can make a difference for |
Right now runtime/src/tools/illink/src/ILLink.Tasks/build/Microsoft.NET.ILLink.targets Lines 217 to 221 in 563408a
This means to make the above rule based on However, it looks like the iOS SDK sets its TrimMode in a MSBuild Target: This means the above rule won't be possible to make without iOS reacting to it. cc @rolfbjarne. We might be saved that So our logic of |
This could be solved if we set |
From the Blazor Webassembly perspective, as long as we can turn it on in the SDK, I think we should be ok. Reflection support is more important for customers apps and third-party libraries that might be making use of it than the framework. I believe in most cases the framework avoids reflection for interop, except for the JS interop mechanism that apps can use to talk to JS from Blazor. That, we don't have control of. |
When you turn it on in the SDK, please make it conditional such the app .csproj can disable it again by overriding the default to get reliable behavior with trimming. We get a steady stream of issues where people are hitting problems due to bad interaction of System.Text.Json with trimming and AOT (for example, #74141). Our default answer has been to use source generators to get reliable behavior with trimming. Our new default answer should be: use source generator and set |
Let's say we turn this off by default for MAUI apps as well, how big of a breaking change do we think it'd be? If the only reliable way is using source generators and JsonSerializerIsReflectionEnabledByDefault=false then maybe we should nudge people into that direction. |
It would break every call to |
I agree with @eerhardt. Enabling this feature is not reasonable for Blazor Webassembly apps, as it will cause an ecosystem breaking change that would force every existing library to update their codebase. In addition to that, for Blazor, we don't give people control over the JSON serialization settings when we are doing JS interop, so there is no way for them to configure this, and is something that we are keen on avoiding, as this contract needs to be implemented both in .NET and JS for interop to work, so we don't want people changing it and breaking framework functionality in subtle/obscure ways. |
@eerhardt seems we can close this? |
Have we settled on a rule yet? I don’t think this can be closed until it gets defaulted for all apps in some form (either AOT or trimmed). I’ve only enabled this for aspnet apps in order to replace aspnet’s temporary feature switch. |
FYI we are planning on turning this after Preview 6 development completes. |
Added
Tagging @dotnet/compat for awareness of the breaking change. |
Originally posted by @eerhardt in #83844 (comment)
The text was updated successfully, but these errors were encountered: