You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[trimming] Enable $(_DefaultValueAttributeSupport) for $(TrimMode)=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]>
Copy file name to clipboardExpand all lines: src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.DefaultProperties.targets
0 commit comments