Skip to content

[Bug]: Duplicate Discriminator Property in Derived Types #9437

@efrainretana

Description

@efrainretana

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

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingemitter:client:csharpIssue for the C# client emitter: @typespec/http-client-csharp

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions