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
{{ message }}
Repository navigation
Trimming: GetObject<T> keeps every constructor of every bound return type again (regression of #10448) #13649
main (trimmable type map, CoreCLR TrimMode=full and NativeAOT)
Description
#10448 removed [DynamicallyAccessedMembers (Constructors)] from Java.Lang.Object.GetObject<T>/_GetObject<T>. Generated bindings call GetObject<T> for every reference-typed return value, so the annotation made the trimmer keep every constructor of every bound return type (dotnet/maui#31316, #10550: about 1 MB of APK growth).
#11801 ("Reflection-free TrimmableTypeMapType/ValueManager") re-added the annotation on both GetObject<T> overloads and on _GetObject<T> (src/Mono.Android/Java.Lang/Object.cs), so the size regression is back. ILC honors the annotation too, so NativeAOT is affected as well.
Example: an app that only reads Context.CacheDir?.AbsolutePath keeps all Java.IO.File constructors: (File, string), (string, string), (URI) and (string). Only the activation constructor (IntPtr, JniHandleOwnership) is needed.
Found by the new tests/TrimmingTests case Cases/BoundReturnTypeConstructors.cs (#13618 follow-up), which is [Ignore]d with a link to this issue. It fails on both CoreCLR full trimming and NativeAOT.
Steps to Reproduce
Create an app whose activity reads CacheDir?.AbsolutePath.
Build Release with TrimMode=full (CoreCLR) or PublishAot=true + IlcGenerateMstatFile=true.
Inspect linked/Mono.Android.dll or the mstat file: all Java.IO.File constructors are present.
Did you find any workaround?
No. The activation path should only need the (IntPtr, JniHandleOwnership) constructor, which the generated type map proxy already references directly. That suggests the annotation on GetObject<T> is unnecessary on the trimmable type map path.
Activity
[tests] Add trimming regression tests for past bugs
[tests] Add trimming regression tests for past bugs
[tests] Add trimming regression tests for past bugs
[tests] Add trimming regression tests for past bugs