dotnet / dotnet/maui

TupleElementNamesAttribute is being trimmed in Android and iOS apps, but BindingExpression relies on it

Open
#4,929 9 comments 0 reactions 0 assignees View on GitHub
area-publishing perf/app-size platform/android platform/ios s/triaged s/verified t/bug
Dominant language
C#
Stars
23.3k
Forks
2k
Avg merge
1d 15h
Merged PRs (30d)
290

Description

### Description

We are getting trimmer warnings here:

```
C:\git\maui\src\Controls\src\Core\BindingExpression.cs(414,5): Trim analysis warning IL2045: Microsoft.Maui.Controls.BindingExpression.SetupPart(TypeInfo,BindingExpression.BindingExpressionPart): Attribute 'System.Runtime.CompilerServices.TupleElementNamesAttribute' is being referenced in code but the trimmer was instructed to remove all instances of this attribute. If the attribute instances are necessary make sure to either remove the trimmer attribute XML portion which removes the attribute instances, or override the removal by using the trimmer XML descriptor to keep the attribute type (which in turn keeps all of its instances). [C:\DotNetTest\MauiTest\MauiTest.csproj]
C:\git\maui\src\Controls\src\Core\BindingExpression.cs(304,4): Trim analysis warning IL2045: Microsoft.Maui.Controls.BindingExpression.SetupPart(TypeInfo,BindingExpression.BindingExpressionPart): Attribute 'System.Runtime.CompilerServices.TupleElementNamesAttribute' is being referenced in code but the trimmer was instructed to remove all instances of this attribute. If the attribute instances are necessary make sure to either remove the trimmer attribute XML portion which removes the attribute instances, or override the removal by using the trimmer XML descriptor to keep the attribute type (which in turn keeps all of its instances). [C:\DotNetTest\MauiTest\MauiTest.csproj]
```

The issue is Android and iOS are setting `System.AggressiveAttributeTrimming=true`, which instructs the trimmer to remove A LOT of attributes, one of them being `TupleElementNamesAttribute`:

https://github.com/dotnet/runtime/blob/95f7f7a026d74e0720d0dfdf2de799933b832df2/src/libraries/System.Private.CoreLib/src/ILLink/ILLink.LinkAttributes.Shared.xml#L119-L337

We should ensure these attributes are preserved for Maui apps in order to keep the following code working correctly in a trimmed app:

https://github.com/dotnet/maui/blob/1cd6ed9e1736f074aa3340c48e5a7913bd77c841/src/Controls/src/Core/BindingExpression.cs#L414-L434

cc @StephaneDelcroix @jonathanpeppers @vitek-karas @marek-safar

### Steps to Reproduce

1. `dotnet new maui`
2. `dotnet restore`
3. `dotnet build -f net6.0-android -r android-arm64 -t:Run -c Release --no-restore -p:SuppressTrimAnalysisWarnings=false -p:TrimmerSingleWarn=false /bl`
4. Inspect the trimmer warnings for mentions of `TupleElementNamesAttribute`.

### Version with bug

Unknown/Other (please specify)

### Last version that worked well

Unknown/Other

### Affected platforms

iOS, Android

### Affected platform versions

All

### Did you find any workaround?

_No response_

### Relevant log output

_No response_

Contributor guide

Open the contributing guide

Research direction

Start with src/Controls/src/Core/BindingExpression.cs around lines 304 and 414-434, then inspect the linked runtime ILLink.LinkAttributes.Shared.xml entries for TupleElementNamesAttribute. Reproduce with the listed net6.0-android Release build command and inspect trim warnings. Done means the relevant attributes are preserved for trimmed Android and iOS apps and the warnings are resolved.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, csharp, ios
Domain
build-system, mobile-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.