-
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
Enable DefaultValueAttributeSupport
in partial trim mode.
#9525
Enable DefaultValueAttributeSupport
in partial trim mode.
#9525
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Is there any way to unit test this on one of our one device tests?
Should we just add Sven's minimal repro: To a new test in a new |
Thanks, added in 14cfd74. What do you think? |
It looks like a We used to share the files between Xamarin & .NET; it could be refactored in the future. |
The failures are related:
|
It passed in Debug mode, which was broken before? This app has android/tests/Mono.Android-Tests/Runtime-Microsoft.Android.Sdk/Mono.Android.NET-Tests.csproj Lines 37 to 39 in a1fab8b
Can the test check a feature flag at runtime (AppContext.TryGetSwitch), and ignore in some cases? Ideally we'd get a green test in Debug and the rest ignore. |
No, it was the release (related to illink) that was broken but the "fix" is only for android/tests/Mono.Android-Tests/Runtime-Microsoft.Android.Sdk/Mono.Android.NET-Tests.csproj Lines 40 to 41 in a1fab8b
Note: I limited the "fix" to partial mode because that's where no trim warnings are shown and yet it failed. In full mode the warnings will show potential issues so that users can add approriate feature switches if needed. |
Let me add an extra test run, that runs the tests with |
…=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 <[email protected]>
Currently, users can experience runtime crashes related to the use of
DefaultValue
attributes (taking type and string) without any trim warnings (see dotnet/runtime#109724). This is because the trim warnings are disable in partial trim mode and this use-case ofDefaultValue
attributes is not trim compatible.Workaround around this is to enable
_DefaultValueAttributeSupport
to prevent customer apps from crashing without trim warnings. App will still crash inTrimMode="full"
but user would get warned during compile time.