Skip to content

[http-client-csharp] Acronym parameter compatibility emits undeclared deserialization variables #11728

Description

@live1206

Describe the bug

The C# generator emits undeclared local variables and substitutes default for constructor arguments when deserializing some models whose property names begin with an acronym such as VMware.

This is a regression between:

  • Microsoft.TypeSpec.Generator.ClientModel 1.0.0-alpha.20260817.7 (commit 1a7f2f4d05e819a8312528e8d207af2f90597d63)
  • Microsoft.TypeSpec.Generator.ClientModel 1.0.0-alpha.20260818.17 (commit a849fcfc965b6dc0cb8dffcb32132e71655a6b4a)

The affected range contains #11714 and its follow-up #11719. In particular, #11714 changed PropertyProvider.AsVariableExpression to reuse AsParameter, while #11719 changed normalization of newly generated property-derived parameters. The combination appears to make deserialization use the normalized/back-compat parameter expression without producing a corresponding local declaration or constructor argument.

Reproduction

Full Azure SDK for .NET regeneration:

Two affected generated models are:

  • InMageRcmFabricCreationContent
  • VMwareCbtEnableMigrationContent

For InMageRcmFabricCreationContent, the previous generator emitted:

ResourceIdentifier vMwareSiteId = default;
// ...
vMwareSiteId = new ResourceIdentifier(prop.Value.GetString());
// ...
return new InMageRcmFabricCreationContent(
    instanceType,
    additionalBinaryDataProperties,
    vMwareSiteId,
    physicalSiteId,
    sourceAgentIdentity);

The new generator emits:

// No vmwareSiteId declaration
// ...
vmwareSiteId = new ResourceIdentifier(prop.Value.GetString());
// ...
return new InMageRcmFabricCreationContent(
    instanceType,
    additionalBinaryDataProperties,
    default,
    physicalSiteId,
    sourceAgentIdentity);

VMwareCbtEnableMigrationContent has the equivalent change from the declared vMwareMachineId local to an undeclared vmwareMachineId, followed by default in the constructor call.

The full repository build fails with:

error CS0103: The name 'vmwareMachineId' does not exist in the current context
error CS0103: The name 'vmwareSiteId' does not exist in the current context

Relevant generated diffs:

Expected behavior

The deserializer should:

  1. Declare exactly one local for each deserialized property.
  2. Assign the JSON value to that local.
  3. Pass that local to the model constructor.
  4. Keep generated local/parameter naming internally consistent regardless of acronym normalization or last-contract parameter spelling.

It must not emit an undeclared assignment or replace a successfully deserialized required value with default.

Impact

The generated SDK does not compile. Independently of the compile error, the generated default constructor argument would discard the deserialized resource identifier.

The management generator's own test suite does not currently cover the combination of acronym-prefixed properties, last-contract constructor compatibility, and model deserialization, so its CI passed while the full Azure SDK regeneration failed.

Related issues: #11696, #11707.

- by copilot

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