Skip to content

[Mgmt Generator] Wrong base class (ArmResource instead of TrackedResourceData) in published npm package #57148

@live1206

Description

@live1206

Minimal Reproduction Spec

Add the following TypeSpec to the mgmt test project (or a standalone spec) and regenerate:

import "@typespec/http";
import "@typespec/rest";
import "@azure-tools/typespec-azure-core";
import "@azure-tools/typespec-azure-resource-manager";

using TypeSpec.Http;
using TypeSpec.Rest;
using Azure.ResourceManager;

@armProviderNamespace
@service({
  title: "Repro Service",
})
@versioned(Versions)
namespace Repro.Service;

enum Versions {
  @useDependency(Azure.ResourceManager.Versions.v1_0_Preview_1)
  v2024_01_01: "2024-01-01",
}

model ReproResource
  is Azure.ResourceManager.TrackedResource<ReproProperties, false> {
  ...ResourceNameParameter<
    Resource = ReproResource,
    KeyName = "reproName",
    SegmentName = "repros"
  >;

  /** The managed service identities assigned to this resource. */
  #suppress "@azure-tools/typespec-azure-resource-manager/arm-resource-invalid-envelope-property"
  identity?: Azure.ResourceManager.CommonTypes.ManagedServiceIdentity;
}

model ReproProperties {
  provisioningState?: string;
  displayName?: string;
}

@armResourceOperations
interface ReproResources {
  get is ArmResourceRead<ReproResource>;
  createOrUpdate is ArmResourceCreateOrUpdateAsync<ReproResource>;
  delete is ArmResourceDeleteWithoutOkAsync<ReproResource>;
  listByResourceGroup is ArmResourceListByParent<ReproResource>;
  listBySubscription is ArmListBySubscription<ReproResource>;
}

Key triggering pattern

The distinguishing factor is the direct identity? envelope property on the resource model:

#suppress "@azure-tools/typespec-azure-resource-manager/arm-resource-invalid-envelope-property"
identity?: Azure.ResourceManager.CommonTypes.ManagedServiceIdentity;

The local test project's JobResource (databox.tsp) uses the same TrackedResource<T, false> base but does not have a direct identity envelope property, and generates correctly with TrackedResourceData as the base class.

Expected output

public partial class ReproResourceData : TrackedResourceData

Actual output (with published npm package)

public partial class ReproResourceData : ArmResource

Bug Description

When regenerating the NewRelic SDK (Azure.ResourceManager.NewRelicObservability) using the published npm package @azure-typespec/http-client-csharp-mgmt@1.0.0-alpha.20260314.2, the generator emits wrong base classes:

  1. NewRelicMonitorResourceData : ArmResource — should be : TrackedResourceData
  2. NewRelicMonitorResource.Serialization.cs redundantly adds : ArmResource to the partial declaration — should only have : IJsonModel<NewRelicMonitorResourceData>

This causes build error CS0115: no suitable method found to override because ArmResource doesn't have JsonModelWriteCore.

Reproduction

  1. Regenerate the NewRelic SDK:
    tsp-client update --output-dir sdk/newrelicobservability/Azure.ResourceManager.NewRelicObservability
    
  2. Build:
    dotnet build sdk/newrelicobservability/Azure.ResourceManager.NewRelicObservability/src
    
  3. Observe CS0115 errors on NewRelicMonitorResourceData.JsonModelWriteCore

Expected Behavior

NewRelicMonitorResourceData should inherit from TrackedResourceData (matching the TypeSpec definition is Azure.ResourceManager.TrackedResource<MonitorProperties, false>).

Investigation Findings

  • The local generator test project (Mgmt-TypeSpec) correctly generates TrackedResourceData for the same pattern (TrackedResource<T, false> in databox.tspJobResourceData : TrackedResourceData).
  • The bug only reproduces when using the published npm package (@azure-typespec/http-client-csharp-mgmt@1.0.0-alpha.20260314.2), not the local build.
  • The bug is likely in the published generator DLL or the @typespec/http-client-csharp@1.0.0-alpha.20260313.1 dependency bundled in the npm package.
  • The mgmt emitter does not modify baseModel — the issue originates upstream in the code model generation.

TypeSpec Definition (NewRelic)

model NewRelicMonitorResource
  is Azure.ResourceManager.TrackedResource<MonitorProperties, false> {
  ...ResourceNameParameter<...>
  identity?: Azure.ResourceManager.CommonTypes.ManagedServiceIdentity;
}

Affected Package

  • @azure-typespec/http-client-csharp-mgmt@1.0.0-alpha.20260314.2
  • SDK: Azure.ResourceManager.NewRelicObservability

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThis issue requires a change to an existing behavior in the product in order to be resolved.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions