Skip to content

LastContractView - Consider Supporting Back Compat Model Ctors #11460

Closed

Description

There's a recent case where a model previously shipped with a property that was required, and a ctor that had a corresponding param that was also required:

public ExecuteDeallocateContent(BulkActionExecutionParameterDetail executionParameters, UserRequestResources resources)

The new version of this library relaxed this req by making the property optional which led to the generator dropping the previous param from the model's ctor. Custom code was required to handle this break:

public ExecuteDeallocateContent(BulkActionExecutionParameterDetail executionParameters, UserRequestResources resources)
            : this(executionParameters)
        {
            if (resources is null)
            {
                throw new ArgumentNullException(nameof(resources));
            }

            Resources = resources;
        }

We should investigate if we can support this case through back compat. We would only be able to restore this ctor if the property name + type didn't change, or a codegentype attribute exists on the new property with a different name but same type.

Activity

  1. github-actions commented on Jul 29, 2026

    @github-actions
    Contributor

    🎯 Issue Triage

    This is a feature request to support back-compat model constructors in the C# client emitter (LastContractView), specifically for cases where a previously required property becomes optional, causing the generated constructor signature to change and break existing user code.

    Category: Feature Request
    Area: emitter:client:csharp

    🔍 Analysis
    • Affected component: C# client emitter (@typespec/http-client-csharp), LastContractView / constructor generation
    • Scenario: When a model property transitions from required → optional, the generator drops the corresponding constructor parameter, which is a breaking change for consumers who used the old constructor signature
    • Proposed mitigation: Restore the old constructor as an overload when the property name + type haven't changed, or when a CodeGenType attribute maps to the same type
    • User impact: Library authors who ship generated clients face downstream breaking changes even for non-breaking API changes; workarounds require custom code
    📝 Suggested next steps
    • Confirm whether LastContractView already captures the previous constructor signatures
    • Define the exact conditions under which the back-compat ctor should be restored (same name + type, or codegentype attribute match)
    • Implement and test the generated back-compat ctor pattern shown in the issue

    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

emitter:client:csharpIssue for the C# client emitter: @typespec/http-client-csharpfeatureNew feature or request

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions