CommunityToolkit / CommunityToolkit/dotnet

Unclear errors on field with ObservableProperty

Open
#947 2 comments 0 reactions 0 assignees View on GitHub
analyzer :eyeglasses: external :arrow_heading_up: mvvm-toolkit :toolbox: need more info :pushpin:
Dominant language
C#
Stars
3.8k
Forks
400
PR merge metrics
No merged PRs in 30d

Description

### Describe the bug

I have a wpf (core based) project, with net6.0 (with visual studio 2022 enterprise), where I installed from nuget the toolkit mvvm version 8.0.0. In the project I have a very basic class that is defined as partial and inherits ObservableObject (just like any guide that explains how to work with the toolkit's MVVM) and contains 3 fields
each wrapped respectively in an ObservableProperty attribute.
When I try to compile I get errors that I have no idea why they actually happen, the errors actually refer to cs g files that are dynamically created using the toolkit, I will give an example for example I have a field in the basic class (called AstroInfo) called star and on it I get an error below that directs it to the g.cs file
The type 'AstroInfo' already contains a definition for 'Star'
In addition to this, more unclear errors in relation to functions that describe events such as
'AstroInfo' already defines a member called 'OnStarChanging' with the same parameter
and-
A partial method may not have multiple defining

I would appreciate guidance in this regard

### Regression

_No response_

### Steps to reproduce

```text
using CommunityToolkit.Mvvm.ComponentModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AstroMatch.Models
{
public partial class AstroInfo : ObservableObject
{
[ObservableProperty]
private string star;

[ObservableProperty]
private int degree;

[ObservableProperty]
private int hour;
}

}
```

### Expected behavior

The compilation goes without any errors

### Screenshots

![image](https://github.com/user-attachments/assets/2bcc53a4-ab19-4cee-8d38-8f142984ba03)

![image](https://github.com/user-attachments/assets/4e0f6868-e3af-4dbc-bcf5-08b92fc08a84)

### IDE and version

VS 2022

### IDE version

_No response_

### Nuget packages

- [ ] CommunityToolkit.Common
- [ ] CommunityToolkit.Diagnostics
- [ ] CommunityToolkit.HighPerformance
- [X] CommunityToolkit.Mvvm (aka MVVM Toolkit)

### Nuget package version(s)

8.0.0

### Additional context

_No response_

### Help us help you

Yes, but only if others can assist

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.