Edit

MVVM Toolkit warning MVVMTK0034

Fields with [ObservableProperty] should not be directly referenced, and the generated properties should be used instead. This warning exists to help avoid cases where developers accidentally refer to backing fields of a generated property to update its value, and then see no property change notification being raised. The generated property should always be referenced instead.

The following sample generates MVVMTK0034:

using CommunityToolkit.Mvvm.ComponentModel;

namespace MyApp;

public partial class SampleViewModel : ObservableObject
{
    [ObservableProperty]
    private string? name;

    public void UpdateName()
    {
        name = Database.LoadUsername();
    }
}

And you can fix it by updating the code as follows:

using CommunityToolkit.Mvvm.ComponentModel;

namespace MyApp;

public partial class SampleViewModel : ObservableObject
{
    [ObservableProperty]
    private string? name;

    public void UpdateName()
    {
        Name = Database.LoadUsername();
    }
}

Additional resources