Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: @typespec/http-client-csharp crashes due to missing package-name in tspconfig.yaml #6212

Open
4 tasks done
YukixPlanet opened this issue Mar 3, 2025 · 2 comments
Open
4 tasks done
Assignees
Labels
bug Something isn't working emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp

Comments

@YukixPlanet
Copy link

YukixPlanet commented Mar 3, 2025

Describe the bug

Bug Description
The emitter @typespec/http-client-csharp crashes during compilation when trying to generate a C# client.
The error message indicates that a required option package-name is missing in the configuration.

Error Message
Emitter "@typespec/http-client-csharp" crashed! This is a bug.
Please file an issue at https://github.com/Microsoft/typespec/issues

Error: Error: Failed to generate the library. Exit code: 1.
StackTrace:
Unable to parse required option package-name from configuration.
at Microsoft.TypeSpec.Generator.Configuration.ReadRequiredStringOption(JsonElement root, String option)
at Microsoft.TypeSpec.Generator.Configuration.Load(String outputPath, String json)
at Microsoft.TypeSpec.Generator.PluginHandler.LoadPlugin(CommandLineOptions options)
at Microsoft.TypeSpec.Generator.GeneratorRunner.RunAsync(CommandLineOptions options)
at Microsoft.TypeSpec.Generator.Program.Run(CommandLineOptions options, GeneratorRunner runner)

Steps to Reproduce
1.Initialize a new TypeSpec project
tsp init
2.Enable the C# client emitter in tspconfig.yaml
emit:
"@typespec/http-client-csharp": true
3.Run TypeSpec compilation
tsp compile .
4.The following error appears:
Unable to parse required option package-name from configuration.

Temporary Workaround
To avoid this error, I commented out @typespec/http-client-csharp in tspconfig.yaml, so it does not run during compilation:
emit:

  • "@typespec/openapi3"
  • // - "@typespec/http-client-csharp"
  • "@typespec/http-server-csharp"

Environment
TypeSpec Compiler Version: 0.65.3
@typespec/http-client-csharp Version: 0.1.9-alpha.20250228.1
Node.js Version: 20.10.0
Operating System: Windows 11

Reproduction

tspconfig.yaml

emit:
  - "@typespec/openapi3"
  - "@typespec/http-client-csharp"
  - "@typespec/http-server-csharp"
options:
  "@typespec/openapi3":
    emitter-output-dir: "{output-dir}/schema"
  "@typespec/http-client-csharp":
    emitter-output-dir: "{output-dir}/clients/csharp"
  "@typespec/http-server-csharp":
    emitter-output-dir: "{output-dir}/server/generated"

main.tsp

import "@typespec/http";
import "@typespec/versioning"; 

using TypeSpec.Http;
using TypeSpec.Versioning; 

@server("https://api.weyi.com/v1", "正式環境")
@server("https://api.develop.com/v1", "測試環境")
@versioned(Versions)
namespace KMArticleSystem {
  enum Versions {
    v1;
    v2;
  }

Checklist

@YukixPlanet YukixPlanet added the bug Something isn't working label Mar 3, 2025
@YukixPlanet YukixPlanet reopened this Mar 3, 2025
@YukixPlanet
Copy link
Author

I accidentally closed this issue. The bug is still reproducible. Please take a look, thank you!

@timotheeguerin timotheeguerin added the emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp label Mar 3, 2025
@JoshLove-msft
Copy link
Contributor

@YukixPlanet, can you try deleting your node_modules folder and rerunning npm install? The name for this option was recently changed but the emitter should be supplying a default value of "package-name" based on the tsp.

@JoshLove-msft JoshLove-msft self-assigned this Mar 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp
Projects
None yet
Development

No branches or pull requests

3 participants