Skip to content

Restore previous parameter names on generated resource and collection methods #11609

Closed

Description

Description

Generated Azure management resource and resource-collection methods do not always restore parameter names from the previous GA contract.

This is source-breaking for callers that use named arguments and is reported by ApiCompat as CP0017.

This is similar to:

However, this case affects generated resource/collection operation methods and the forwarding methods generated on parent resources.

Reproduction

In Azure/azure-sdk-for-net, build:

dotnet build .\sdk\redis\Azure.ResourceManager.Redis\src\Azure.ResourceManager.Redis.csproj --nologo

The build fails with 36 CP0017 errors across netstandard2.0, net8.0, and net10.0.

Representative errors:

Parameter name on member 'Azure.ResourceManager.Redis.RedisResource.GetRedisPatchScheduleAsync(RedisPatchScheduleDefaultName, CancellationToken)' changed from 'defaultName' to 'default'.
Parameter name on member 'Azure.ResourceManager.Redis.RedisPatchScheduleCollection.CreateOrUpdateAsync(WaitUntil, RedisPatchScheduleDefaultName, RedisPatchScheduleData, CancellationToken)' changed from 'defaultName' to 'default'.
Parameter name on member 'Azure.ResourceManager.Redis.RedisPatchScheduleCollection.GetIfExists(RedisPatchScheduleDefaultName, CancellationToken)' changed from 'defaultName' to 'default'.

Affected collection methods include CreateOrUpdate[Async], Get[Async], Exists[Async], and GetIfExists[Async]. The parent RedisResource.GetRedisPatchSchedule[Async] forwarding methods are also affected.

The newly generated signatures use:

RedisPatchScheduleDefaultName @default

while the previous GA contract used:

RedisPatchScheduleDefaultName defaultName

Other generated surfaces, such as RedisPatchScheduleResource.CreateResourceIdentifier and ArmRedisModelFactory.RedisPatchScheduleData, preserve defaultName, which isolates the gap to resource/collection operation methods.

Root-cause theory

The shared C# generator has general method parameter-name restoration in BackCompatHelper.RestorePreviousParameterNames, invoked by TypeProvider.BuildMethodsForBackCompatibility.

The management providers also call the base implementation:

  • ResourceCollectionClientProvider.BuildMethodsForBackCompatibility
  • ResourceClientProvider.BuildMethodsForBackCompatibility

Despite that, the previous name is not restored for these methods. The affected methods are synthesized management wrappers rather than the original convenience methods:

  1. ResourceOperationMethodProvider builds collection/resource signatures from convenience-method parameters through OperationMethodParameterHelper.GetOperationMethodParameters.
  2. ResourceClientProvider.BuildGetChildResourceMethods creates parent-resource forwarding methods by copying the generated collection method signature.
  3. Because the synthesized resource/collection parameter is not matched to the corresponding previous-contract parameter, the shared restoration leaves default unchanged.
  4. The forwarding methods then propagate the same unrestored parameter name.

The likely missing case is therefore parameter-name restoration for synthesized resource/collection operation methods where input-parameter provenance and/or positional signature matching does not resolve to the previous contract. This should be handled by the base generator rather than with Redis-specific customization.

The relevant general method back-compat work is #10988 and #11491, but this resource/collection shape is still not covered.

Expected behavior

When a generated public/protected resource or collection method has the same method name and positional C# parameter types as the previous contract, restore the previous parameter names, including C# keyword stabilization such as default -> defaultName.

Forwarding resource methods should inherit the restored collection parameter names.

Suggested tests

  • A ResourceCollectionClientProvider operation with a path parameter whose current name is a C# keyword and whose previous name was keyword-suffixed.
  • CreateOrUpdate, Get, Exists, and GetIfExists sync/async methods.
  • The corresponding parent-resource forwarding Get<Resource>[Async] methods.
  • Verify that the restored parameter provider remains connected to XML docs and method-body arguments.

Activity

  1. github-actions commented on Aug 10, 2026

    @github-actions
    Contributor

    🎯 Issue Triage

    The C# client emitter fails to restore previous GA parameter names on synthesized resource and collection operation methods, causing CP0017 ApiCompat errors. The root cause is that BackCompatHelper.RestorePreviousParameterNames does not cover methods built by ResourceOperationMethodProvider, leaving C# keyword-escaped names like @default unrestored to their previous GA names (e.g., defaultName).

    Category: Bug

    Area: emitter:client:csharp

    ⚠️ No TypeSpec reproduction provided — this is a C# emitter back-compat issue reproducible by building Azure.ResourceManager.Redis in azure-sdk-for-net.

    🔍 Analysis
    • Affected methods: CreateOrUpdate[Async], Get[Async], Exists[Async], GetIfExists[Async] on ResourceCollection providers, plus parent-resource forwarding methods from ResourceClientProvider.BuildGetChildResourceMethods.
    • Root cause: ResourceOperationMethodProvider synthesizes method parameters via OperationMethodParameterHelper.GetOperationMethodParameters, bypassing the positional matching used by BackCompatHelper.RestorePreviousParameterNames. Forwarding methods then copy the unrestored signature.
    • Not affected: CreateResourceIdentifier and model factory methods already restore defaultName correctly, isolating the gap to resource/collection operation methods.
    • Related issues: Restore previous GA parameter names on generated constructors #11588 (same class of bug for constructors), feat: generalize back compat #10988 and fix: relax back compat param name matching #11491 (general back-compat method parameter name work that did not cover this shape).
    📝 Suggested next steps
    • Extend BackCompatHelper.RestorePreviousParameterNames (or add a parallel hook) to cover parameters produced by ResourceOperationMethodProvider.
    • Ensure ResourceClientProvider.BuildGetChildResourceMethods propagates restored names from the collection method signature.
    • Add tests as suggested in the issue: ResourceCollectionClientProvider operation with a C# keyword path parameter, covering sync/async variants of CreateOrUpdate, Get, Exists, GetIfExists, and parent forwarding methods.

    Generated by Agentic Triage

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

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