Skip to content

TodoApp.Uno: MVVMTK0045 - ObservableProperty field pattern not WinRT/AOT-safe on windows head #538

Description

@adrianhall

Summary

ViewModels/TodoListViewModel.cs uses the older [ObservableProperty] private <type> <field>; pattern from CommunityToolkit.Mvvm, which produces this warning on the net10.0-windows10.0.26100 head:

ViewModels/TodoListViewModel.cs(21,18): warning MVVMTK0045: The field TodoApp.Uno.ViewModels.TodoListViewModel.isRefreshing using [ObservableProperty] will generate code that is not AOT compatible in WinRT scenarios (such as UWP XAML and WinUI 3 apps), and a partial property should be used instead ...
ViewModels/TodoListViewModel.cs(27,20): warning MVVMTK0045: ... TodoListViewModel.title ...
ViewModels/TodoListViewModel.cs(24,63): warning MVVMTK0045: ... TodoListViewModel.items ...

CI run: https://github.com/CommunityToolkit/Datasync/actions/runs/29093946725 (todoapp-uno / windows job)

This is pre-existing sample code, unrelated to #524/#525/#526 (PR #533) - it's just newly visible now that CI builds the windows head as part of the todoapp-uno job for the first time (previously blocked by #525's build failure on the other heads before the whole job could be wired in).

Root cause

CommunityToolkit.Mvvm's source generator warns that the field-based [ObservableProperty] private bool isRefreshing; pattern isn't safe for AOT-published, WinRT-marshalled scenarios (WinUI 3 / UWP), because CsWinRT's generators need a partial property (not a private field) to produce correct WinRT marshalling code. Today this is diagnostic-only: the sample is built (not AOT-published) in CI, so there's no functional impact yet, but it's the officially recommended modern MVVM Toolkit pattern regardless of AOT.

Affected fields in TodoListViewModel.cs: isRefreshing, items, title.

Suggested fix

Convert each field to the modern partial-property pattern, e.g.:

[ObservableProperty]
private bool isRefreshing;

becomes

[ObservableProperty]
public partial bool IsRefreshing { get; set; }

...and update any internal references from the lowercase backing-field name to the generated PascalCase property name (most usages should already be going through the generated property rather than the field directly). Apply to isRefreshing, items, and title in TodoListViewModel.cs.

Metadata

Metadata

Assignees

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions