Skip to content

Improve conflicting member exception message#38222

Open
m-x-shokhzod wants to merge 1 commit intodotnet:mainfrom
m-x-shokhzod:fix/conflicting-member-exception-message
Open

Improve conflicting member exception message#38222
m-x-shokhzod wants to merge 1 commit intodotnet:mainfrom
m-x-shokhzod:fix/conflicting-member-exception-message

Conversation

@m-x-shokhzod
Copy link
Copy Markdown
Contributor

When adding a member with a name that already exists, the previous exception only stated "a property or navigation with the same name already exists" without distinguishing what kind of member the conflict was with, and unconditionally included the declaring type even when it was the same as the type being added to.

Address the three improvements requested in #36487:

  1. Specify the kind of the conflicting member (property, complex property, navigation, skip navigation, or service property).
  2. Include the declaring type only when it differs from the current type — split into two resources, ConflictingPropertyOrNavigation for same-type conflicts and ConflictingPropertyOrNavigationOnBaseType for conflicts inherited from a base type.
  3. Add explicit removal guidance: "Remove the existing X first."

Add two helpers in PropertyBaseExtensions:

  • GetMemberKindString returns the human-readable kind label.
  • FormatConflictingMemberMessage picks the right resource based on declaring-type-vs-current-type and assembles the message.

Update all eight throw sites to use the helper (or the new resource directly when the conflicting member is not in scope).

Update affected tests to assert against the new messages.

@m-x-shokhzod m-x-shokhzod requested a review from a team as a code owner May 5, 2026 10:35
When adding a member with a name that already exists, the previous
exception only stated "a property or navigation with the same name
already exists" without distinguishing what kind of member the conflict
was with, and unconditionally included the declaring type even when it
was the same as the type being added to.

Address the three improvements requested in dotnet#36487:

  1. Specify the kind of the conflicting member (property, complex
     property, navigation, skip navigation, or service property).
  2. Include the declaring type only when it differs from the current
     type — split into two resources, ConflictingPropertyOrNavigation
     for same-type conflicts and ConflictingPropertyOrNavigationOnBaseType
     for conflicts inherited from a base type.
  3. Add explicit removal guidance: "Remove the existing X first."

Add two helpers in PropertyBaseExtensions:
  - GetMemberKindString returns the human-readable kind label.
  - FormatConflictingMemberMessage picks the right resource based on
    declaring-type-vs-current-type and assembles the message.

Update all eight throw sites to use the helper (or the new resource
directly when the conflicting member is not in scope).

Update affected tests to assert against the new messages.

Fixes dotnet#36487
@m-x-shokhzod m-x-shokhzod force-pushed the fix/conflicting-member-exception-message branch from 5379f2a to 9425fcf Compare May 5, 2026 12:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants