Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 27, 2026

Derived types incorrectly re-declare discriminator properties when the base class has a discriminator with a different C# name but the same serialized name (e.g., base has Type@odata.type, derived has OdataType@odata.type). This causes CS0108 "hides inherited member" compiler warnings.

Changes

  • ModelProvider.BuildProperties(): Extended discriminator skip logic to check serialized names in addition to C# property names
  • Tests: Added two test cases covering both same-name and different-name scenarios with matching serialized names

Before

// Only checked C# property name
if (isDiscriminator && baseProperties.ContainsKey(property.Name))

After

// Also check serialized name to handle different C# names with same wire name
HashSet<string> baseDiscriminatorSerializedNames = EnumerateBaseModels()
    .SelectMany(m => m.Properties)
    .Where(p => p.IsDiscriminator)
    .Select(p => p.SerializedName)
    .ToHashSet();

if (isDiscriminator && (baseProperties.ContainsKey(property.Name) || 
    baseDiscriminatorSerializedNames.Contains(property.SerializedName)))
Original prompt

This section details on the original issue you should resolve

<issue_title>[Bug]: Duplicate Discriminator Property in Derived Types</issue_title>
<issue_description>### Describe the bug

Description

The TypeSpec C# generator creates a duplicate OdataType property in derived classes when the base class already defines it as the discriminator. This causes CS0108 "hides inherited member" compiler warnings/errors.

Reproduction

In ContentUnderstandingSkill.cs (derived from SearchIndexerSkill):

Base class (SearchIndexerSkill.cs):

internal string OdataType { get; set; }

Derived class (ContentUnderstandingSkill.cs) incorrectly re-declares:

internal string OdataType { get; set; } = "#Microsoft.Skills.Util.ContentUnderstandingSkill";

The internal constructor also has a redundant parameter:

internal ContentUnderstandingSkill(
    string odataType,           // ? passed to base class
    ...,
    string odataType0)          // ? duplicate, assigned to local OdataType
    : base(odataType, ...)
{
    // ...
    OdataType = odataType0;     // ? This shouldn't exist
}

Expected Behavior

Derived types should NOT re-declare the discriminator property. The value should be set via the base class constructor only, which is already being done correctly in the public constructor:

public ContentUnderstandingSkill(...) 
    : base("#Microsoft.Skills.Util.ContentUnderstandingSkill", inputs, outputs)

Compiler Error

CS0108: 'ContentUnderstandingSkill.OdataType' hides inherited member 'SearchIndexerSkill.OdataType'. 
Use the new keyword if hiding was intended.

Root Cause

The TypeSpec definition likely has the @odata.type discriminator property appearing in both the base type and derived type definitions, or there's a conflict between the discriminator and a regular property with the same JSON name.

Affected Types

  • ContentUnderstandingSkill
  • ChatCompletionSkill
  • Potentially all derived skill types and any other polymorphic hierarchy with a discriminator property

Reproduction

Existing File with error : https://github.com/Azure/azure-sdk-for-net/blob/3df80e71cc22102f60910e9d188ca864ea18849d/sdk/search/Azure.Search.Documents/src/Generated/Models/ChatCompletionSkill.cs#L138C1-L139C1

Previous file: https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/search/Azure.Search.Documents/src/Generated/Models/ChatCompletionSkill.cs

Checklist

<agent_instructions>This fix applies to packages\http-client-csharp</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits January 27, 2026 19:04
…ialized names

When a derived model has a discriminator property with a different C# name but the
same serialized name as the base model's discriminator, the property was incorrectly
being generated in the derived class, causing CS0108 "hides inherited member" warnings.

The fix adds a check for serialized names in addition to C# property names when
determining if a discriminator property should be skipped in derived types.

Co-authored-by: JonathanCrd <17486462+JonathanCrd@users.noreply.github.com>
…iltering

Co-authored-by: JonathanCrd <17486462+JonathanCrd@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix duplicate OdataType property in derived types Fix duplicate discriminator property in derived types with matching serialized names Jan 27, 2026
Copilot AI requested a review from JonathanCrd January 27, 2026 19:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Duplicate Discriminator Property in Derived Types

2 participants