CommunityToolkit / CommunityToolkit/dotnet

Partial ObservableProperty in ObservableObject shows error CS0229 ambiguity between property and property

Open
#1,056 11 comments 1 reaction 0 assignees View on GitHub
bug :bug:
Dominant language
C#
Stars
3.8k
Forks
400
PR merge metrics
No merged PRs in 30d

Description

### Describe the bug

I'm developing a WinUI application with Community Toolkit MVVM 8.4.0.
I switched the properties in my application to use the new format. Here's one example:

```
[ObservableProperty]
public partial bool Returned { get; set; } = returned;
```
And this is a simplified version of the constructor for the object:
`public partial class Item(bool returned) : ObservableObject`

This all works as expected and compiles fine but all uses of the property elsewhere show the Compiler Error CS0229. In this case it shows:
`Ambiguity between Item.Returned and Item.Returned.`
I only have the one property called Returned.
As I said, it all compiles fine and works correctly but I'm not able to get rid of the error.

### Regression

_No response_

### Steps to reproduce

Create a class with the type ObservableObject and create a partial Observable Property. Use it elsewhere in the app.

Example:
```
public partial class Item(bool returned) {
[ObservableProperty]
public partial bool Returned { get; set; } = returned;
}
```
Then access the property somewhere else in the app.

Example:
```
var newItem = new Item(false);
newItem.Returned = true;
```
This shows the compiler error.

### Expected behavior

I would like to remove the false alarm.

### Screenshots

![Image](https://github.com/user-attachments/assets/a62c181d-9654-42a5-8ab4-c09f0af10e2f)

### IDE and version

VS 2022

### IDE version

Version 17.13.1

### Nuget packages

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

### Nuget package version(s)

8.4.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.