Skip to content

[Bug]: Inconsistent Variable Naming in Deserialization Methods #9436

@efrainretana

Description

@efrainretana

Describe the bug

Description

The TypeSpec C# generator produces inconsistent variable names in the Deserialize* methods. A local variable is declared with one name but referenced with a different name later in the method.

Reproduction

In IndexingParametersConfiguration.Serialization.cs:

// Line 176 - variable declared as 'additionalProperties'
IDictionary<string, BinaryData> additionalProperties = new ChangeTrackingDictionary<string, BinaryData>();

// ... many lines later ...

// Line 301 - referenced as 'additionalBinaryDataProperties' (WRONG!)
additionalBinaryDataProperties.Add(prop.Name, BinaryData.FromString(prop.Value.GetRawText()));

Expected Behavior

The variable name should be consistent throughout the method. Either:

  • Declare as additionalBinaryDataProperties and use additionalBinaryDataProperties, OR
  • Declare as additionalProperties and use additionalProperties

Root Cause

The generator uses different naming conventions in different parts of the serialization template:

  • One part uses the pattern matching the field name (_additionalBinaryDataProperties ? additionalBinaryDataProperties)
  • Another part uses a simpler name (additionalProperties)

Affected Types

  • IndexingParametersConfiguration
  • FacetResult
  • Potentially any type with additional/unknown properties handling

Reproduction

steps: Regenerate SDK on Azure.Search.Documents.

Existing: https://github.com/Azure/azure-sdk-for-net/blob/3df80e71cc22102f60910e9d188ca864ea18849d/sdk/search/Azure.Search.Documents/src/Generated/Models/FacetResult.Serialization.cs#L222C1-L223C1

Repo: https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/search/Azure.Search.Documents/src

Checklist

Metadata

Metadata

Assignees

No one assigned

    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