Esri / arcgis-maps-sdk-dotnet-toolkit

Toolkit for ArcGIS Maps SDK for .NET
https://esri.github.io/arcgis-maps-sdk-dotnet-toolkit/
Apache License 2.0
217 stars 121 forks source link

Not trimmer friendly in .NET 8 #538

Closed espenrl closed 9 months ago

espenrl commented 11 months ago

Hi, I'm experiencing some issues with trimming on iOS and Android using toolkit 200.3.0.

ILLink : error IL2036: Esri.ArcGISRuntime.Toolkit.Maui.Primitives.AttachmentsPopupElementView.BuildDefaultItemTemplate(): Unresolved type 'Esri.ArcGISRuntime.Toolkit.Maui.Primitives.AttachmentViewModel' in 'DynamicDependencyAttribute'.
ILLink : error IL2037: Esri.ArcGISRuntime.Toolkit.Maui.OverviewMap..cctor(): No members were resolved for 'LoadStatus' on type 'Esri.ArcGISRuntime.Mapping.Map'. 

Temporary fix

<PropertyGroup>
    <NoWarn>$(NoWarn);IL2036;IL2037</NoWarn>
</PropertyGroup>

Investigation

https://github.com/Esri/arcgis-maps-sdk-dotnet-toolkit/blob/8117823c0bcb48b22e4b7b9102936557de0fd8fb/src/Toolkit/Toolkit/UI/Controls/PopupViewer/AttachmentsPopupElementView.Maui.cs#L76-L80

AttachmentViewModel is a private class nested inside AttachmentsPopupElementView. I guess the full type name is incorrect.

https://github.com/Esri/arcgis-maps-sdk-dotnet-toolkit/blob/8117823c0bcb48b22e4b7b9102936557de0fd8fb/src/Toolkit/Toolkit/UI/Controls/PopupViewer/AttachmentsPopupElementView.Maui.cs#L189-L194

I haven't investigated the second error..

dotMorten commented 10 months ago

Good find! You're right the full type name is incorrect for AttachmentViewModel. The other one I think it just need to change from Map.LoadStatus to GeoModel.LoadStatus https://github.com/Esri/arcgis-maps-sdk-dotnet-toolkit/blob/8117823c0bcb48b22e4b7b9102936557de0fd8fb/src/Toolkit/Toolkit.Maui/OverviewMap/OverviewMap.cs#L36

Having said that, trimming in .NET MAUI is still pretty limited and causing a lot of issues beyond the .NET SDKs's own libraries - even .NET MAUI has lots of issues and are still working through it. Generally I'd recommend turning trimming off for Esri.ArcGISRuntime since especially bindings are causing a lot of issues since MAUI can't properly analyze and preserve properties you're binding to. If you want to keep trimming on for our libraries, expect doing a lot of these DynamicDependency attributes for things you bind to but don't access directly in code-behind, and as this issue shows, it can be pretty error-prone.