Skip to content

MauiXamlInflator break communitytoolkit.mvvm's source generator in iOS release aot mode #33489

@jingliancui

Description

@jingliancui

Description

https://learn.microsoft.com/en-us/dotnet/maui/xaml/xamlc?view=net-maui-10.0#enable-source-generation-and-per-file-settings

https://learn.microsoft.com/en-us/dotnet/communitytoolkit/mvvm/generators/overview

Some background:
My app already used communitytoolkit.mvvm‘s source generator in .net9, then I update the app to .net10 and config MauiXamlInflator.
When I want to publish to app store, but the build show the warning and all the binding were gone after run the app:
warning IL2026: Using member 'Microsoft.Maui.Controls.Binding.Binding(String, BindingMode, IValueConverter, Object, String, Object)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Using bindings with string paths is not trim safe. Use expression-based binding instead.

Steps to Reproduce

SampleApp.zip

  1. Open the app using vscode
  2. Set the debug mode to "Release"
  3. Run to the device(my device is iphone12 ios 26.2)

Expect:

All text should be hidden.

Click the button should show the text.

Actual:

All text will be shown.

Click the button do not show/hide the text.

Link to public reproduction project repository

https://github.com/jingliancui/MauiXamlInflatorIssue

Version with bug

10.0.20

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

iOS

Affected platform versions

iOS 26.2

Did you find any workaround?

remove below config:

	<PropertyGroup>
		<MauiXamlInflator>SourceGen</MauiXamlInflator>
	</PropertyGroup>

Relevant log output

*  Executing task: dotnet build -t:Build -p:Configuration=Release -f net10.0-ios -r ios-arm64 -p:CustomAfterMicrosoftCSharpTargets=/Users/ericcui/.vscode/extensions/ms-dotnettools.dotnet-maui-1.12.15-darwin-arm64/dist/resources/Custom.After.Microsoft.CSharp.targets -p:MauiVSCodeBuildOutputFile=/var/folders/81/70kf_yv12x1c7nrdnd3m6vrw0000gn/T/dotnet-maui/maui-vsc-5f8d2af3-e04b-4231-a219-a8c4c4c881c3.json -p:MauiTargetProject=/Users/ericcui/Desktop/releaseissue/SampleApp/SampleApp.csproj -p:XamlTools=/Users/ericcui/.vscode/extensions/ms-dotnettools.csharp-2.110.4-darwin-arm64/.xamlTools -p:EnableDiagnostics=True -p:EnableMauiXamlDiagnostics=True /Users/ericcui/Desktop/releaseissue/SampleApp/SampleApp.csproj 

  SampleApp net10.0-ios ios-arm64 succeeded with 2 warning(s) (151.2s) → bin/Release/net10.0-ios/ios-arm64/SampleApp.dll
    /Users/ericcui/Desktop/releaseissue/SampleApp/obj/Release/net10.0-ios/ios-arm64/Microsoft.Maui.Controls.SourceGen/Microsoft.Maui.Controls.SourceGen.XamlGenerator/MainPage.xaml.xsg.cs(82,21): warning IL2026: Using member 'Microsoft.Maui.Controls.Binding.Binding(String, BindingMode, IValueConverter, Object, String, Object)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Using bindings with string paths is not trim safe. Use expression-based binding instead.
    /Users/ericcui/Desktop/releaseissue/SampleApp/obj/Release/net10.0-ios/ios-arm64/Microsoft.Maui.Controls.SourceGen/Microsoft.Maui.Controls.SourceGen.XamlGenerator/MainPage.xaml.xsg.cs(109,22): warning IL2026: Using member 'Microsoft.Maui.Controls.Binding.Binding(String, BindingMode, IValueConverter, Object, String, Object)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Using bindings with string paths is not trim safe. Use expression-based binding instead.

Build succeeded with 2 warning(s) in 151.3s
 *  Terminal will be reused by tasks, press any key to close it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-xamlXAML, CSS, Triggers, Behaviorsplatform/ioss/triagedIssue has been revieweds/verifiedVerified / Reproducible Issue ready for Engineering Triaget/bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions