Skip to content

ObservableProperty not generated for WPF application targeting .NET Framework 4.8 #695

@smaugbend

Description

@smaugbend

In the Introduction to the MVVM Toolkit Microsoft Learn article (version from January 12, 2023 retrieved on May 12, 2023), it is stated that

This package targets .NET Standard so it can be used on any app platform: UWP, WinForms, WPF, Xamarin, Uno, and more; and on any runtime: .NET Native, .NET Core, .NET Framework, or Mono. It runs on all of them.

which seems to indicate that this Community Toolkit should work in an application using WPF that targets .NET Framework 4.8.

If this is the case, then I believe there is a bug present in the version 8.2.0 NuGet package.

The issue is that the code for an ObservableProperty of an ObservableObject (such as in the example in the ObservablePropertyAttribute Class documentation) does not get generated when building a WPF application that targets .NET Framework 4.8.

The attached WpfApp1 Visual Studio 2022 Solution is a minimal reproducible example wherein Class1 is an ObservableObject with an ObservableProperty and the App.OnStartup method attempts to use the Class1.Name property that is supposed to be generated.

Attempting to Build Solution yields

error CS1061: 'Class1' does not contain a definition for 'Name' and no accessible extension method 'Name' accepting a first argument of type 'Class1' could be found (are you missing a using directive or an assembly reference?)

and is preventing my utilization of this feature.

WpfApp1.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    mvvm-toolkit 🧰Issues/PRs for the MVVM Toolkitnot an issue ❌An issue outside of the scope of the .NET Community Toolkit

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions