Skip to content

[Bug]: http-server-csharp: Generated createdbyType.cs has incorrect file name, XML doc #11536

Closed

Description

Describe the bug

The following file is generated:

generated@typespec\http-server-csharp\generated\models\createdByType.cs

with the following contents:

// Generated by @typespec/http-server-csharp
// <auto-generated />
#nullable enable

using System.Text.Json;
using System.Text.Json.Serialization;

namespace Microsoft.Throttling;

[JsonConverter(typeof(JsonStringEnumConverter))]
/// <summary>
/// The kind of entity that created the resource.
/// </summary>
public enum CreatedByType
{
    /// <summary>
    /// The entity was created by a user.
    /// </summary>
    [JsonStringEnumMemberName("User")]
    User,
    /// <summary>
    /// The entity was created by an application.
    /// </summary>
    [JsonStringEnumMemberName("Application")]
    Application,
    /// <summary>
    /// The entity was created by a managed identity.
    /// </summary>
    [JsonStringEnumMemberName("ManagedIdentity")]
    ManagedIdentity,
    /// <summary>
    /// The entity was created by a key.
    /// </summary>
    [JsonStringEnumMemberName("Key")]
    Key
}

Note a few issues:

  1. camel casing of the file: createdByType.cs
  2. The XML doc is below attribute [JsonConverter]
  3. Unused usings: using System.Text.Json; (minor; might be needed by other generated files)
  4. Unncessary attrubyte [JsonStringEnumMemberName] (since the enum member exactly matches the name being passed; but again - minor and might be needed by other generated files)

Reproduction

emit:

  • "@typespec/http-server-csharp"
    options:
    "@typespec/http-server-csharp":
    emitter-output-dir: "{project-root}/generated/{emitter-name}"
    output-type: all

Checklist

Activity

  1. github-actions commented on Aug 4, 2026

    @github-actions
    Contributor

    🎯 Issue Triage

    The @typespec/http-server-csharp emitter generates createdByType.cs with incorrect camelCase filename (should be CreatedByType.cs), and places the [JsonConverter] attribute above the XML doc comment block instead of below it.

    Category: Bug

    Area: emitter:service:csharp

    🔍 Analysis

    Affected component: @typespec/http-server-csharp emitter

    Issues identified:

    1. File naming: createdByType.cs — C# convention requires PascalCase filenames matching the type name: CreatedByType.cs
    2. XML doc placement: The [JsonConverter(typeof(JsonStringEnumConverter))] attribute is emitted before the XML doc comment (/// ...). In C#, XML documentation comments must appear immediately before the declaration, so attributes should come after the docs or the docs will not be correctly associated.
    3. (Minor) Unused using System.Text.Json; import
    4. (Minor) Redundant [JsonStringEnumMemberName] attributes where member name matches the string value

    The root cause is in the code generation logic for enum types in the C# service emitter — specifically how file paths are computed and how attributes/docs are ordered during output rendering.

    📝 Suggested next steps
    • Fix file name generation to use PascalCase for enum types (and verify consistency across all generated type files)
    • Fix ordering: emit XML doc comments before attributes in enum and possibly other type declarations
    • (Optional) Suppress redundant [JsonStringEnumMemberName] when name matches value exactly

    Generated by Agentic Triage

  2. timotheeguerin commented on Aug 7, 2026

    @timotheeguerin
    Member

    Not sure if that is the exact same repro but seems like we just don't apply naming policy on the file

    enum camelEnum {}
    model camelModel {}
    
    Image

    playground

  3. linked a pull request that will close this issueFix C# server model filenames #11591on Aug 7, 2026
  4. added a commit that references this issue on Aug 28, 2026
    5cea376
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions