-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
[iOS] Resolving Trimming Warnings for dotnet new maui
#19397
Labels
area-publishing
Issues with the app packaging/publishing process (ipk/apk/msix/trimming)
fixed-in-9.0.0-preview.3.10457
platform/iOS 🍎
Milestone
Comments
simonrozsival
added
platform/iOS 🍎
area-publishing
Issues with the app packaging/publishing process (ipk/apk/msix/trimming)
labels
Dec 13, 2023
4 tasks
This was referenced Jan 5, 2024
This was referenced Jan 15, 2024
This was referenced Feb 8, 2024
This was referenced Mar 6, 2024
jonathanpeppers
pushed a commit
that referenced
this issue
Mar 11, 2024
Contributes to: #19397 _Trim analyzer_ is reporting the following warnings: ``` /obj/Release/net9.0-maccatalyst/maccatalyst-arm64/Microsoft.Maui.Controls.SourceGen/Microsoft.Maui.Controls.SourceGen.CodeBehindGenerator/Resources_Styles_Colors.xaml.sg.cs(30,4): warning IL2026: Using member 'Microsoft.Maui.Controls.Xaml.Extensions.LoadFromXaml<TXaml>(TXaml, Type)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Loading XAML at runtime might require types and members that cannot be statically analyzed. Make sure all of the required types and members are preserved. ``` It is safe to suppress the warnings in the `InitializeComponent` method because its method body will be replaced with `XamlC` in Release builds.
All trimming warnings in the template app have been resolved. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
area-publishing
Issues with the app packaging/publishing process (ipk/apk/msix/trimming)
fixed-in-9.0.0-preview.3.10457
platform/iOS 🍎
Trimming unused code from libraries used in an application is crucial to minimize deployment size. One of our goals for .NET 9 is to make MAUI trimming-friendly (#18658).
Publishing the base MAUI app
dotnet new maui
for iOS with NativeAOT currently emits 69 warnings (64 Trim analysis warnings + 5 AOT analysis warnings). Our first goal is to make the codepaths used in the base MAUI app trimming and AOT friendly (0 warnings).Once the template MAUI app is warning-free, we will move onto more complex scenarios (possibly WeatherTwentyOne or eShop ClientApp).
Build steps
./bin/dotnet/dotnet publish \ -f net8.0-ios \ -r ios-arm64 \ -p:PublishAot=true \ -p:PublishAotUsingRuntimePack=true \ -p:_RequireCodeSigning=false \ -p:EnableTrimAnalyzer=true \ -p:TrimmerSingleWarn=false | tee TestApp.log
Warnings (grouped by class or namespace)
System.Activator.CreateInstance(Type)
without aDynamicallyAccessedMemberTypes.PublicParameterlessConstructor
type.Type.GetType(String)
to grab aMicrosoft.Maui.Controls.*
type.System.Activator.CreateInstance(Type,Object[])
without aDynamicallyAccessedMemberTypes.PublicConstructors
typeSystem.Activator.CreateInstance(Type)
without aDynamicallyAccessedMemberTypes.PublicParameterlessConstructor
typeList<Types> DependencyTypes
's elements aren'tDynamicallyAccessedMembers
TypesSystem.Activator.CreateInstance(Type)
without aDynamicallyAccessedMemberTypes.PublicParameterlessConstructor
type.RegisterRoute(string, [DynamicallyAccessedMembers...] Type)
is accessed through reflection.[QueryProperty]
#20466System.Object.GetType()
does not return[DynamicallyAccessedMembers] Type
required bySystem.Reflection.RuntimeReflectionExtensions.GetRuntimeProperty(Type,String)
System.Reflection.Assembly.GetExportedTypes()
from an overriddenConvertFrom(ITypeDescriptorContext,CultureInfo,object)
andConvertTo(ITypeDescriptorContext,CultureInfo,object,Type)
which aren't decorated withRequiresUnreferencedCodeAttribute
System.Reflection.Assembly.GetExportedTypes()
is not decorated withDynamicallAccessedMemberTypes.PublicParameterlessConstructor
Microsoft.Maui.Controls.Xaml.TypeConversionExtensions.GetImplicitConversionOperator(Type,Type,Type)
typeName
of methodSystem.Type.GetType(String)
System.Activator.CreateInstance(Type)
without aDynamicallyAccessedMemberTypes.PublicParameterlessConstructor
type.System.Reflection.RuntimeReflectionExtensions.GetRuntimeEvents(Type)
with a Type not decorated withDynamicallyAccessedMemberTypes.PublicEvents | DynamicallyAccessedMemberTypes.NonPublicEvents
System.Reflection.RuntimeReflectionExtensions.GetRuntimeEvent(Type,String)
with a String not decorated withDynamicallyAccessedMemberTypes.PublicEvents
System.Reflection.RuntimeReflectionExtensions.GetRuntimeMethods(Type)
for a type not decorated withDynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.NonPublicMethods
System.Reflection.RuntimeReflectionExtensions.GetRuntimeProperties(Type)
with a Type not decorated withDynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.NonPublicProperties
System.Type.GetFields(BindingFlags)
with a Type not decorated withDynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFieldsInvokes
System.Type.GetInterfaces()
with a Type not decorated withDynamicallyAccessedMemberTypes.Interfaces
System.Type.GetMethod(String,BindingFlags)
with a Type not decorated withDynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.NonPublicMethods
System.Type.GetProperty(String,BindingFlags)
with a Type not decorated withDynamicallyAccessedMemberTypes.PublicProperties
System.Activator.CreateInstance(Type)
with a Type not decorated withDynamicallyAccessedMemberTypes.PublicParameterlessConstructor
System.Activator.CreateInstance(Type,Object[])
with a Type not decorated with DynamicallyAccessedMemberTypes.PublicConstructorsSystem.Reflection.TypeInfo.DeclaredConstructors.get
with a TypeInfo not decorated withDynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors
System.Reflection.RuntimeReflectionExtensions.GetRuntimeMethods(Type)
with a Type not decorated withDynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.NonPublicMethods
System.Activator.CreateInstance(Type)
with a Type not decorated withDynamicallyAccessedMemberTypes.PublicParameterlessConstructor
System.Type.GetType(String)
System.Type.MakeGenericType(Type[])
System.Type.MakeGenericType(Type[])
System.Type.GetInterfaces()
with a Type not decorated withDynamicallyAccessedMemberTypes.Interfaces
System.Type.GetInterfaces(String)
with a Type not decorated withDynamicallyAccessedMemberTypes.Interfaces
System.Type.MakeGenericType(Type[])
System.Type.GetInterfaces()
with a Type not decorated withDynamicallyAccessedMemberTypes.Interfaces
System.Activator.CreateInstance(Type)
with a Type not decorated withDynamicallyAccessedMemberTypes.PublicParameterlessConstructor
System.Reflection.TypeInfo.DeclaredFields.get
with a TypeInfo not decorated withDynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields
System.Reflection
APIs (DeclaredProperties.get
,ImplementedInterfaces.get
,GetDeclaredMethod(String)
,GetDeclaredProperty(String)
GetDeclaredField(String)
) with aTypeInfo
not decorated withDynamicallyAccessedMemberTypes
<Module>..cctor()
- 1System.Enum.GetValues(Type)
Automated testing
There is a test that counts the warnings in the MAUI app (introduced in #19194). PRs which fix any of the warnings should update the list of expected warnings.
/cc @jonathanpeppers @mdh1418 @ivanpovazan
The text was updated successfully, but these errors were encountered: