Skip to content

SourceGen warning MAUIG2045 with RelayCommand and Async postfix #34029

@zwikk

Description

@zwikk

Description

The latest 10.0.40 release has a regression bug where the XAML source generator doesn't play nice with the source generator of CommunityToolkit.Mvvm.

Consider the following viewmodel where the command DoSomethingCommand is generated:

public partial class MainViewModel : ObservableObject
{
  [RelayCommand]
  private Task DoSomethingAsync()
  {
    return Task.CompletedTask;
  }
}

And the following XAML button binding the command:

<Button  Command="{Binding DoSomethingCommand}" />

Enable SourceGen in csproj:

<MauiXamlInflator>SourceGen</MauiXamlInflator>

With MAUI 10.0.40 the following build warning is emitted:

Warning MAUIG2045 : Binding: Property "DoSomethingCommand" not found on "global::xx.MainViewModel". The binding will use slower reflection-based binding at runtime. If this property is generated by another source generator, consider reporting this at https://github.com/dotnet/maui/issues to help us improve source generator interoperability.

With warning-as-error, this results in an error.

Steps to Reproduce

  1. Clone the repro project
  2. Build
  3. Observe the build error (TreatWarningsAsError is enabled)

Link to public reproduction project repository

https://github.com/zwikk/maui-playground/tree/main/Source/SourceGenCommand

Version with bug

10.0.40

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

Last version that worked well

10.0.30

Affected platforms

iOS, Android, macOS

Affected platform versions

Any

Did you find any workaround?

There are 3 workarounds I know of.

  • Remove the Async suffix
  • Disable SourceGen
  • Revert back to 10.0.30

Relevant log output

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions