Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error CS0229 : Ambiguity on partial props with primary constructor #76949

Open
jasonmsmith opened this issue Jan 16, 2025 · 1 comment
Open
Labels
Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead

Comments

@jasonmsmith
Copy link

jasonmsmith commented Jan 16, 2025

Describe the bug

The error occurs in a very specific situation:

  1. The class must contain at least one partial property. (In my tests, the definition and implementation were in separate files)
  2. The class must have a primary constructor
  3. Use the nameof operator to refer to one of the partial properties of the class from the constructor of an attribute attached to a class. (It is important that the nameof operator is used outside of any class definitions. nameof works as expected inside the bounds of a class definition.)

When these three conditions are met, dotnet build fails with Error CS0229, claiming ambiguity between the two halves of the partial property.

To Reproduce

You can see a simple class library here: https://github.com/jasonmsmith/PartialPropertyTest

Note that there are two nearly identical classes, one with a standard constructor and the other with a primary constructor. The one with a primary constructor causes an error on build, but not the one with a standard constructor.

Exceptions (if any)

N/A

Further technical details

dotnet --info
.NET SDK:
Version: 9.0.101
Commit: eedb237549
Workload version: 9.0.100-manifests.1e472b70
MSBuild version: 17.12.12+1cce77968

Runtime Environment:
OS Name: Windows
OS Version: 10.0.22631
OS Platform: Windows
RID: win-x64
Base Path: C:\Program Files\dotnet\sdk\9.0.101\

.NET workloads installed:
[android]
Installation Source: SDK 9.0.100, VS 17.9.34723.18
Manifest Version: 35.0.24/9.0.100
Manifest Path: C:\Program Files\dotnet\sdk-manifests\9.0.100\microsoft.net.sdk.android\35.0.24\WorkloadManifest.json
Install Type: Msi

[ios]
Installation Source: SDK 9.0.100, VS 17.9.34723.18
Manifest Version: 18.2.9170/9.0.100
Manifest Path: C:\Program Files\dotnet\sdk-manifests\9.0.100\microsoft.net.sdk.ios\18.2.9170\WorkloadManifest.json
Install Type: Msi

[maccatalyst]
Installation Source: SDK 9.0.100, VS 17.9.34723.18
Manifest Version: 18.2.9170/9.0.100
Manifest Path: C:\Program Files\dotnet\sdk-manifests\9.0.100\microsoft.net.sdk.maccatalyst\18.2.9170\WorkloadManifest.json
Install Type: Msi

[maui-windows]
Installation Source: SDK 9.0.100, VS 17.9.34723.18
Manifest Version: 9.0.0/9.0.100
Manifest Path: C:\Program Files\dotnet\sdk-manifests\9.0.100\microsoft.net.sdk.maui\9.0.0\WorkloadManifest.json
Install Type: Msi

Configured to use loose manifests when installing new manifests.

Host:
Version: 9.0.0
Architecture: x64
Commit: 9d5a6a9aa4

.NET SDKs installed:
8.0.202 [C:\Program Files\dotnet\sdk]
8.0.404 [C:\Program Files\dotnet\sdk]
9.0.101 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 6.0.28 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 9.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.28 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 9.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 6.0.28 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 7.0.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 8.0.3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 8.0.11 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 9.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
x86 [C:\Program Files (x86)\dotnet]
registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables:
Not set

global.json file:
Not found

Learn more:
https://aka.ms/dotnet/info

Download .NET:
https://aka.ms/dotnet/download

  • The IDE (VS / VS Code/ VS4Mac) you're running on, and its version: Jetbrains Rider 2024.3.3. However, the issue persists when running dotnet build from the command line.
@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged Issues and PRs which have not yet been triaged by a lead label Jan 16, 2025
@KalleOlaviNiemitalo
Copy link

This is similar to #76651; not exactly the same, but might have the same root cause.

@marcpopMSFT marcpopMSFT transferred this issue from dotnet/sdk Jan 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

No branches or pull requests

2 participants