Skip to content

Update the MAUI sample to CSLA 11 with trimming and NativeAOT - #4973

Draft
rockfordlhotka wants to merge 7 commits into
mainfrom
4970-maui-sample-csla11-trim-aot
Draft

rockfordlhotka wants to merge 7 commits into
mainfrom
4970-maui-sample-csla11-trim-aot

Conversation

@rockfordlhotka

Copy link
Copy Markdown
Member

Moves Samples/MauiExample to CSLA 11 and sets it up to publish with full trimming on Android and NativeAOT on iOS and Mac Catalyst, with no IL warnings. It also fixes an IL2112 that Csla.Xaml (MAUI) causes in any trimmed app that uses csla:PropertyInfo.

Draft: the last commits add a temporary macOS workflow (.github/workflows/maui-sample-aot.yaml) used to verify the NativeAOT builds. It will be removed before this is marked ready. The app still needs a run on a device or simulator.

Sample changes

  • Reference Csla and Csla.Maui 11.0.0-alpha.1 and remove the retired Csla.Generator.AutoImplementProperties.CSharp package
  • Bump Microsoft.Maui.Controls to 10.0.120 and Microsoft.Extensions.Logging.Debug to 10.0.14, the minimums Csla.Maui 11.0.0-alpha.1 requires (older pins fail restore with NU1605)
  • PersonList is partial (CSLA0024); PersonEdit.Fetch assigns Id and Name instead of calling DataMapper.Map, which is [RequiresUnreferencedCode]
  • TrimMode=full on Android, PublishAot=true on iOS and Mac Catalyst (NativeAOT already trims every assembly, and the iOS SDK warns if TrimMode is set with it), TrimmerSingleWarn=false, and IsAotCompatible on BusinessLibrary and DataAccess; the stale net9.0 property groups are removed
  • Keep csla:PropertyInfo, with one justified IL2026 suppression scoped to PersonEditPage.InitializeComponent. That method is generated from the XAML, so the suppression is declared at assembly level with a Target
  • Styles.xaml uses the <OnPlatform> element; the template's {OnPlatform} markup extension caused an IL2026 on its Default
  • Use the non-generic RefreshAsync (the MAUI part of Use non-generic RefreshAsync in samples when they move to CSLA 11 #4961; the SaveAsync/ManageObjectLifetime behavior review stays there)
  • New readme.md covering the settings, the CSLA trimming rules the sample follows, and how to publish each platform

Framework fix: IL2112 in Csla.Xaml (MAUI)

PropertyInfo has a class-level [RequiresUnreferencedCode], which also covers its static BrokenRulesProperty field. MAUI's VisualElement has [DynamicallyAccessedMembers(PublicFields | NonPublicFields)], which reaches that field, so the trimmer reports IL2112 against Csla.Xaml in every trimmed app that uses the control. The field now has an UnconditionalSuppressMessage for IL2112: its static initializer only creates the BindableProperty and doesn't walk a binding path. The justification is in TrimmingMessages.cs. Avalonia's base types have no such annotation, so only MAUI is affected.

Release note: Csla.Xaml.Maui Release builds against the published Csla package, and 11.0.0-alpha.1 doesn't have the new TrimmingMessages constant. So the Csla.Maui Release build won't compile until the next Csla prerelease ships and the Release reference is bumped to it, the same order used for 11.0.0-alpha.1 (#4971). CI builds MAUI in Debug, so it isn't affected. Until that release, the sample, which references alpha.1, reports this one IL2112 on Android publish; the readme says so.

Testing

  • dotnet build Samples/MauiExample/MauiExample.sln -c Debug: 0 errors. The only warnings are the iOS/Mac Catalyst "no connection to a Mac" messages (no CS0618, CSLA0024 or IL warnings)
  • dotnet build Source/csla.build.sln and Source/csla.maui.build.sln: no CS or IL warnings (csla.build has its existing MSB3277/NU19xx/NU1510 restore and reference warnings only)
  • Android, fully trimmed, against Csla/Csla.Maui packed from this branch: 0 IL warnings. Confirmed trimming ran (PropertyInfo and ViewModelBase kept, unused PropertyStatus removed). Against published alpha.1: only the IL2112 fixed here
  • iOS simulator and Mac Catalyst, NativeAOT, on macOS (temporary workflow, against packages from this branch): both succeed with 0 IL warnings, and neither app bundle contains managed assemblies, which confirms NativeAOT compiled them. The workflow builds the iOS simulator app with _IsPublishing=true, because dotnet publish only accepts device RIDs, and it uses Xcode 26.5 with ValidateXcodeVersion=false because this runner image has no simulator runtime for Xcode 26.0
  • Still to do: run the app on a device or simulator and check list, edit, save and the validation messages

Closes #4970
Partially addresses #4961 (MAUI RefreshAsync calls)

🤖 Generated with Claude Code

rockfordlhotka and others added 7 commits October 29, 2026 10:21
- Reference the Csla and Csla.Maui 11.0.0-alpha.1 packages and drop the
  retired AutoImplementProperties generator package
- Declare PersonList partial and replace DataMapper.Map with explicit
  property assignments in PersonEdit
- Publish with TrimMode=full on Android and iOS and NativeAOT on iOS and
  Mac Catalyst; set TrimmerSingleWarn=false and IsAotCompatible on the
  libraries; remove the stale net9.0 property groups
- Suppress the csla:PropertyInfo IL2026 on PersonEditPage's generated
  InitializeComponent, and use the trim safe OnPlatform element in Styles.xaml
- Use the non-generic RefreshAsync (MAUI part of #4961)
- Add a readme covering the settings and CSLA rules

Csla.Xaml (MAUI): suppress IL2112 on PropertyInfo.BrokenRulesProperty.
The class-level RequiresUnreferencedCode covers the static field, which
MAUI's VisualElement [DynamicallyAccessedMembers] reaches; its initializer
doesn't walk a binding path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Remove before merging.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…lator in the temp workflow

NativeAOT links every assembly and the iOS SDK warns when TrimMode is set
with it. dotnet publish rejects simulator RIDs, so the temporary workflow
builds with _IsPublishing=true and checks the bundles have no managed
assemblies.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@rockfordlhotka

Copy link
Copy Markdown
Member Author

@Bowman74 can you help me test this? My new PC has an arm64 processor and so apparently can't run android emulators, and I've never been able to run iOS stuff - but hopefully this PR enables AOT trimming for MAUI.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The new constant reference is missing from MAUI’s Csla 11.0.0-alpha.1 dependency, breaking MAUI Release builds and blocking Csla.Maui packaging.

1 open issue
What changed in this PR

Updates the MAUI sample to CSLA 11 and demonstrates full trimming on Android and NativeAOT on Apple platforms. It also adds a targeted suppression for the framework’s MAUI PropertyInfo trimming warning.

Changes:

  • Updates dependencies and business classes for CSLA 11.
  • Enables trimming/AOT settings, replaces reflection-based mapping, and documents publishing.
  • Adds a temporary macOS workflow to verify NativeAOT output and check for IL warnings.
File Description
Source/​Csla/​Core/​TrimmingMessages.cs Adds the bindable-field suppression justification.
Source/​Csla.Xaml.Shared/​PropertyInfo.cs Suppresses MAUI-specific IL2112 on BrokenRulesProperty.
Samples/​MauiExample/​readme.md Documents trimming rules and publish commands.
Samples/​MauiExample/​MauiExample/​Resources/​Styles/​Styles.xaml Uses the trim-safe OnPlatform element.
Samples/​MauiExample/​MauiExample/​Pages/​PersonListPage.xaml.cs Uses non-generic RefreshAsync.
Samples/​MauiExample/​MauiExample/​Pages/​PersonEditPage.xaml.cs Updates refresh calls and scopes the XAML warning suppression.
Samples/​MauiExample/​MauiExample/​MauiExample.csproj Updates packages and enables platform-specific trimming/AOT.
Samples/​MauiExample/​DataAccess/​DataAccess.csproj Enables trim and AOT analysis.
Samples/​MauiExample/​BusinessLibrary/​PersonList.cs Makes the list partial for operation generation.
Samples/​MauiExample/​BusinessLibrary/​PersonEdit.cs Replaces reflective mapping with explicit assignments.
Samples/​MauiExample/​BusinessLibrary/​BusinessLibrary.csproj Updates CSLA, removes the retired generator, and enables AOT analysis.
.github/​workflows/​maui-sample-aot.yaml Adds temporary Apple NativeAOT verification.

Review effort: Balanced

Comment thread Source/Csla.Xaml.Shared/PropertyInfo.cs Resolved

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update the MAUI sample to CSLA 11 with trimming and NativeAOT

2 participants