{"record":{"id":"534fd6fc863b2b47","repo":"clockworklabs/SpacetimeDB","slug":"namespace-is-only-supported-with-lang-csharp","errorCode":null,"errorMessage":"--namespace is only supported with --lang csharp","messagePattern":"--namespace is only supported with --lang csharp","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/cli/src/subcommands/generate.rs","lineNumber":486,"sourceCode":"    entry\n}\n\npub async fn run_prepared_generate_configs(\n    run_configs: Vec<GenerateRunConfig>,\n    extract_descriptions: ExtractDescriptions,\n    json_module: Option<Vec<PathBuf>>,\n    force: bool,\n    namespace_from_cli: bool,\n) -> anyhow::Result<()> {\n    for run in run_configs {\n        println!(\n            \"Generating {} module bindings for module {}\",\n            run.lang.display_name(),\n            run.project_path.display()\n        );\n\n        if namespace_from_cli && run.lang != Language::Csharp {\n            return Err(anyhow::anyhow!(\"--namespace is only supported with --lang csharp\"));\n        }\n\n        let module: ModuleDef = if let Some(paths) = &json_module {\n            let DeserializeWrapper::<RawModuleDef>(module) = if let Some(path) = paths.first() {\n                serde_json::from_slice(&fs::read(path)?)?\n            } else {\n                serde_json::from_reader(std::io::stdin().lock())?\n            };\n            module.try_into()?\n        } else {\n            let path = if let Some(path) = &run.wasm_file {\n                println!(\"Skipping build. Instead we are inspecting {}\", path.display());\n                path.clone()\n            } else if let Some(path) = &run.js_file {\n                println!(\"Skipping build. Instead we are inspecting {}\", path.display());\n                path.clone()\n            } else {\n                let (path, _) =","sourceCodeStart":468,"sourceCodeEnd":504,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/524b4487d949b61a07d4f39c862d1290259dfd20/crates/cli/src/subcommands/generate.rs#L468-L504","documentation":"The `--namespace` flag renames the generated C# namespace and only the C# codegen understands it. generate iterates every resolved run config, and if the flag came from the CLI while any run's language is not C#, that run aborts with this error. A `namespace` set inside a csharp target in spacetime.json is fine for multi-target setups because it is scoped to that target.","triggerScenarios":"`spacetime generate --namespace MyCo.MyApp --lang typescript`; a multi-target spacetime.json containing rust and csharp targets invoked with the `--namespace` CLI flag.","commonSituations":"Teams sharing one spacetime.json across several language targets passing a CLI flag intended for only one of them; copy-pasting a C# invocation while iterating on other targets.","solutions":["Remove `--namespace` from the CLI invocation","Move the namespace into the csharp target: `\"namespace\": \"MyCo.MyApp\"` in spacetime.json","Generate the C# target separately: `spacetime generate --lang csharp --namespace MyCo.MyApp --database <db>`"],"exampleFix":"# before\nspacetime generate --namespace MyCo.MyApp   # fails when any target is not csharp\n\n# after — spacetime.json\n{\n  \"generate\": { \"targets\": [\n    { \"database\": \"mydb\", \"lang\": \"rust\", \"out-dir\": \"src/generated\" },\n    { \"database\": \"mydb\", \"lang\": \"csharp\", \"namespace\": \"MyCo.MyApp\", \"out-dir\": \"module_bindings\" }\n  ] }\n}\n\n# then: spacetime generate --database mydb","handlingStrategy":"validation","validationCode":"# Only add --namespace when every target being generated is csharp:\nset -- $(jq -r '.generate.targets[]? | select((.database // \"*\") == \"mydb\") | .lang' spacetime.json)\nfor lang in \"$@\"; do\n  [[ \"$lang\" == csharp ]] || { echo \"--namespace skipped: target lang=$lang\" >&2; NS_ARG=(); break; }\ndone\nspacetime generate --database mydb \"${NS_ARG[@]}\"","typeGuard":"// Rust: only the csharp codegen accepts a namespace.\nfn allows_namespace(lang: &str) -> bool {\n    lang.eq_ignore_ascii_case(\"csharp\")\n}","tryCatchPattern":null,"preventionTips":["Scope namespaces to the csharp target in spacetime.json instead of a global CLI flag","Generate non-C# targets in a separate invocation without --namespace"],"tags":["namespace","csharp","generate","flag-combination"],"backgroundTag":"unsupported-flag-combination","analyzedSha":"524b4487d949b61a07d4f39c862d1290259dfd20","analyzedAt":"2026-08-16T23:58:54.611Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}