microsoft / microsoft/typespec

[Bug]: http-server-csharp: Generated model file has unknown using TypeSpec.Helpers

Open
#11,446 1 comment 1 reaction 0 assignees View on GitHub
bug emitter:service:csharp triaged:core
Dominant language
Java
Stars
5.9k
Forks
394
Avg merge
1d 23h
Merged PRs (30d)
104

Description

### Describe the bug

Example:

```csharp
// Generated by @typespec/http-server-csharp
//
#nullable enable

using System;
using System.Collections.Generic;
using System.Text.Json;
using System.Text.Json.Serialization;
using TypeSpec.Helpers;
using TypeSpec.Helpers.JsonConverters;
// ^ The type or namespace name 'TypeSpec' could not be found (are you missing a using directive or an assembly reference?)

namespace Microsoft.MyRpNamespace;

public partial class Model5
{
}
```

### Reproduction

1. Use an ARM RP typespec
2. Add the following to tspconfig.yaml

```yml
emit:
- "@typespec/http-server-csharp"
options:
"@typespec/http-server-csharp":
emitter-output-dir: "{project-root}/generated/{emitter-name}"
output-type: all
emit-mocks: none
overwrite: true
```

### Checklist

- [x] Follow our [Code of Conduct](https://github.com/microsoft/typespec/blob/main/CODE_OF_CONDUCT.md)
- [x] Check that there isn't already an issue that request the same bug to avoid creating a duplicate.
- [x] Check that this is a concrete bug. For Q&A open a [GitHub Discussion](https://github.com/Microsoft/typespec/discussions).
- [x] The provided reproduction is a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) of the bug.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the issue with an ARM RP TypeSpec project using the shown tspconfig.yaml and the @typespec/http-server-csharp emitter. Inspect the generated model file and the emitter output for the TypeSpec.Helpers imports. Done means the generated C# model no longer references the unavailable TypeSpec.Helpers namespaces and compiles without the reported error.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
65/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.