-
Notifications
You must be signed in to change notification settings - Fork 518
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
[net10.0] Aggressive attribute trimming breaks NativeAOT builds #22065
Comments
Isn't the workaround setting the feature to |
jonathanpeppers
added a commit
to dotnet/maui
that referenced
this issue
Jan 28, 2025
Context: xamarin/xamarin-macios#22065 The introduction of a new `$(MobileAggressiveAttributeTrimming)` MSBuild property in .NET 10 breaks NativeAOT builds in two ways: * C# attributes are stripped away by ILLink, hence: * Trimmer warnings are introduced. * App crashes can result, with IL removed that *shouldn't* be. Let's set `$(MobileAggressiveAttributeTrimming)` to `false` for now to avoid these issues. In a future PR, we can address xamarin-macios#22065 in the iOS workload.
rmarinho
pushed a commit
to dotnet/maui
that referenced
this issue
Jan 28, 2025
Context: xamarin/xamarin-macios#22065 The introduction of a new `$(MobileAggressiveAttributeTrimming)` MSBuild property in .NET 10 breaks NativeAOT builds in two ways: * C# attributes are stripped away by ILLink, hence: * Trimmer warnings are introduced. * App crashes can result, with IL removed that *shouldn't* be. Let's set `$(MobileAggressiveAttributeTrimming)` to `false` for now to avoid these issues. In a future PR, we can address xamarin-macios#22065 in the iOS workload.
If we really need this (personally I would prefer slightly bigger apps which work more often, over slightly smaller apps which break more often, but this is up to the iOS team to decide) I think we should make two changes to this:
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Apple platform
Mac Catalyst, iOS
Framework version
net10.0-*
Affected platform version
.NET 10 P1
Description
The recent addition of the switch/build property
MobileAggressiveAttributeTrimming
which enables aggressive attribute trimming in .NET 10 (#21314) causes problems with NativeAOT builds. This problem surfaced in dotnet/maui#27103When the feature switch is enabled (the default behavior), ILLink removes all
[DynamicallyAccessedMembers]
and when ILC builds a NativeAOT binary, it cannot see these annotations anymore and it produces trim warnings and the final binary most likely won't work as expected.I see two possible fixes:
MobileAggressiveAttributeTrimming
for NativeAOT builds and let ILC trim unnecessary attributesDynamicallyAccessedMembersAttribute
fromTrimAttributes.LinkDescription.xml
.System.Diagnostics.CodeAnalysis
namespace for static analysis of the program, such as theFeatureGuardAttribute
./cc @rolfbjarne @jonathanpeppers @sbomer
Steps to Reproduce
<PublishAot Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">true</PublishAot>
to the project filenet10.0
branch with this command:$(MAUI_DIR)/dotnet-local.sh publish -f net10.0-maccatalyst -r maccatalyst-arm64 -p:TrimmerSingleWarn=false
Did you find any workaround?
Set
$(MobileAggressiveAttributeTrimming)=false
in the MAUI project.Build logs
The text was updated successfully, but these errors were encountered: