Partial ObservableProperty in ObservableObject shows error CS0229 ambiguity between property and property
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
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
Confirmation
I am also experiencing this issue in the same conditions.
Steps to Reproduce
I have an ObservableProperty named FullName defined in an ObservableObject extending class Process.cs, as defined below:
/// <summary>
/// [Observable] A reference-friendly Process name in the form of "Code-Title".
/// </summary>
[ObservableProperty]
public partial string FullName {get; set;} = $"{Code}-{Title}";
When I attempt to access this property in my ViewModel class, like so:
/// <summary>
/// Serves the Process masterlist as a list of Process Full Name strings.
/// </summary>
public List<string> ProcessNames {
get => Processes.Select(x => x.FullName).ToList();
}
My IDE shows this error:
Ambiguity between 'Process.FullName' and 'Process.FullName' CS0229
string Process.FullName { get; set; }
'FullName' is not null here.
Environment Details
IDE:
Visual Studio Code
Version: 1.98.2 (user setup)
Commit: ddc367ed5c8936efe395cffeec279b04ffd7db78
Date: 2025-03-12T13:32:45.399Z
Electron: 34.2.0
ElectronBuildId: 11161602
Chromium: 132.0.6834.196
Node.js: 20.18.2
V8: 13.2.152.36-electron.0
OS: Windows_NT x64 10.0.26100
CommunityToolkit:
<PackageReference Include="CommunityToolkit.Maui" Version="11.1.0" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0" />
.NET Info:
.NET SDK:
Version: 9.0.104
Commit: 2750432faa
Workload version: 9.0.100-manifests.5c4e24dc
MSBuild version: 17.12.27+e0b90a9a8
Runtime Environment:
OS Name: Windows
OS Version: 10.0.26100
OS Platform: Windows
RID: win-x64
Base Path: C:\Program Files\dotnet\sdk\9.0.104\
.NET workloads installed:
[maui]
Installation Source: SDK 9.0.100
Manifest Version: 9.0.14/9.0.100
Manifest Path: C:\Program Files\dotnet\sdk-manifests\9.0.100\microsoft.net.sdk.maui\9.0.14\WorkloadManifest.json
Install Type: Msi
Configured to use loose manifests when installing new manifests.
Host:
Version: 9.0.3
Architecture: x64
Commit: 831d23e561
.NET SDKs installed:
9.0.104 [C:\Program Files\dotnet\sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 9.0.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.14 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 9.0.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 8.0.14 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 9.0.3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Other architectures found:
None
Environment variables:
Not set
global.json file:
Not found
"This all works as expected and compiles fine but all uses of the property elsewhere show the Compiler Error CS0229"
That's very weird. I also can't repro and I never saw this happen. @CyrusNajmabadi do you think this might be an IDE bug? Should they report this in VS Feedback?
Confirmation
I am also experiencing this issue in the same conditions.
...
Update
Oddly enough, I have another ObservableObject, Part.cs, with identical implementation. When I attempt to reference this class, I can. I'm including the source for each of these classes to compare.
Class Implementations
Process.cs:
using CommunityToolkit.Mvvm.ComponentModel;
namespace LotCoMPrinter.Models.Datasources;
...
public partial class Process(string Code, string Title, string Type, List<Part> Parts): ObservableObject {
...
[ObservableProperty]
public partial string Code {get; set;} = Code;
...
[ObservableProperty]
public partial string Title {get; set;} = Title;
...
[ObservableProperty]
public partial string FullName {get; set;} = $"{Code}-{Title}";
...
[ObservableProperty]
public partial string Type {get; set;} = Type;
...
[ObservableProperty]
public partial List<Part> Parts {get; set;} = Parts;
}
Part.cs
using CommunityToolkit.Mvvm.ComponentModel;
namespace LotCoMPrinter.Models.Datasources;
...
public partial class Part(string ParentProcess, string PartNumber, string PartName, string ModelNumber): ObservableObject {
...
[ObservableProperty]
public partial string ParentProcess {get; set;} = ParentProcess;
...
[ObservableProperty]
public partial string PartNumber {get; set;} = PartNumber;
...
[ObservableProperty]
public partial string PartName {get; set;} = PartName;
...
[ObservableProperty]
public partial string ModelNumber {get; set;} = ModelNumber;
}
Conditions of Functioning Reference
This method, in my ViewModel class, is able to reference Part.ModelNumber (via the SelectedPart property with type Part):
...
private async Task<Tuple<string, List<string>>> SerializeLabel(...) {
...
// serialize the label if needed
// This reference to SelectedProcess (type Process) throws IDE warning
if (SelectedProcess!.Type.Equals("Originator")) {
string? SerialNumber;
// assign/retrieve a cached serial number for this label
// This reference does not throw IDE warning
SerialNumber = await Serializer.Serialize(UICapture[1].Replace("Part: ", ""), SelectedPart!.ModelNumber, SerializeMode, BasketType);
...
}
...
}
That's very weird. I also can't repro and I never saw this happen. @CyrusNajmabadi do you think this might be an IDE bug? Should they report this in VS Feedback?
@Sergio0694 I have a feeling it may be. I tried to run my app, ignoring the problem warnings. The app builds and runs with no related warnings or errors.
Looks like updating to Visual Studio 2022 preview 17.14 fixes this issue: https://github.com/dotnet/roslyn/issues/76949
I have the same bug in VS Community v17.13.5
same here
hello... any update?
repro is provided. @Sergio0694 vs2022 17.14.11 win11 24h2