-
Notifications
You must be signed in to change notification settings - Fork 533
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
[.NET 10] change default value for PublishTrimmed
#9526
Labels
Area: App+Library Build
Issues when building Library projects or Application projects.
Milestone
Comments
jonathanpeppers
added
the
Area: App+Library Build
Issues when building Library projects or Application projects.
label
Nov 19, 2024
dotnet-policy-service
bot
added
the
needs-triage
Issues that need to be assigned.
label
Nov 19, 2024
jonathanpeppers
added a commit
that referenced
this issue
Nov 20, 2024
…=partial` (#9525) Context: dotnet/runtime#109724 In .NET 9, certain apps could crash with: System.ArgumentException: RuntimeInstanceNotAllowed ?, in object DefaultValueAttribute.get_Value() ?, in new XmlAttributes(ICustomAttributeProvider) ?, in XmlAttributes XmlReflectionImporter.GetAttributes(MemberInfo) ?, in bool XmlReflectionImporter.InitializeStructMembers(StructMapping, StructModel, bool, string, RecursionLimiter) ?, in StructMapping XmlReflectionImporter.ImportStructLikeMapping(StructModel, string, bool, XmlAttributes, RecursionLimiter) .NET's concept of `$(PublishTrimmed)` is used to decide which trimmer feature switches are toggled. This is normally set for both Debug & Release, but Android only sets it for Release. This means that the `$(_DefaultValueAttributeSupport)` feature switch is not set properly in some cases, which causes the crash. For now, we can set `$(_DefaultValueAttributeSupport)` for `TrimMode=partial`, the default in .NET MAUI apps. See #9526 for how we might better address this in the future. In order to test this change: * Add a `XmlSerializerTest` to `Mono.Android-Tests` * Run a copy of `Mono.Android-Tests` with `-p:TestsFlavor=TrimModePartial` * Also set `$(_DefaultValueAttributeSupport)` for `TrimMode=full` in our test project, so `XmlSerializerTest` will pass in that mode as well. Co-authored-by: Jonathan Peppers <jonathan.peppers@microsoft.com>
jonathanpeppers
added a commit
that referenced
this issue
Nov 20, 2024
…=partial` (#9525) Context: dotnet/runtime#109724 In .NET 9, certain apps could crash with: System.ArgumentException: RuntimeInstanceNotAllowed ?, in object DefaultValueAttribute.get_Value() ?, in new XmlAttributes(ICustomAttributeProvider) ?, in XmlAttributes XmlReflectionImporter.GetAttributes(MemberInfo) ?, in bool XmlReflectionImporter.InitializeStructMembers(StructMapping, StructModel, bool, string, RecursionLimiter) ?, in StructMapping XmlReflectionImporter.ImportStructLikeMapping(StructModel, string, bool, XmlAttributes, RecursionLimiter) .NET's concept of `$(PublishTrimmed)` is used to decide which trimmer feature switches are toggled. This is normally set for both Debug & Release, but Android only sets it for Release. This means that the `$(_DefaultValueAttributeSupport)` feature switch is not set properly in some cases, which causes the crash. For now, we can set `$(_DefaultValueAttributeSupport)` for `TrimMode=partial`, the default in .NET MAUI apps. See #9526 for how we might better address this in the future. In order to test this change: * Add a `XmlSerializerTest` to `Mono.Android-Tests` * Run a copy of `Mono.Android-Tests` with `-p:TestsFlavor=TrimModePartial` * Also set `$(_DefaultValueAttributeSupport)` for `TrimMode=full` in our test project, so `XmlSerializerTest` will pass in that mode as well. Co-authored-by: Jonathan Peppers <jonathan.peppers@microsoft.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Android framework version
net9.0-android
Affected platform version
any
Description
Context: #9525
Context: dotnet/runtime#109724
As seen in the above issue, there is currently the expectation in .NET:
PublishTrimmed=true
set for all configurations, it means "I intend to trim this project"illink
. For console apps,dotnet build
doesn't trim orillink
,dotnet publish
does trim and runillink
.PublishTrimmed
Unfortunately, Android doesn't follow this pattern:
PublishTrimmed=false
for build performance, inner loopPublishTrimmed=true
To fix this in .NET 10, we should:
PublishTrimmed=true
alwaysillink
in Debug mode via other meansSteps to Reproduce
dotnet new android
dotnet build
(debug mode)Did you find any workaround?
For the case above you could set
$(_DefaultValueAttributeSupport)
as done in #9525.The text was updated successfully, but these errors were encountered: