-
Notifications
You must be signed in to change notification settings - Fork 334
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
ContentUnderstandingSkillChatCompletionSkill- 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
- Follow our Code of Conduct
- Check that there isn't already an issue that request the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion.
- The provided reproduction is a minimal reproducible example of the bug.