clockworklabs/SpacetimeDB · error · anyhow::Error

--namespace is only supported with --lang csharp

Error message

--namespace is only supported with --lang csharp

What it means

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.

Source

Thrown at crates/cli/src/subcommands/generate.rs:486

    entry
}

pub async fn run_prepared_generate_configs(
    run_configs: Vec<GenerateRunConfig>,
    extract_descriptions: ExtractDescriptions,
    json_module: Option<Vec<PathBuf>>,
    force: bool,
    namespace_from_cli: bool,
) -> anyhow::Result<()> {
    for run in run_configs {
        println!(
            "Generating {} module bindings for module {}",
            run.lang.display_name(),
            run.project_path.display()
        );

        if namespace_from_cli && run.lang != Language::Csharp {
            return Err(anyhow::anyhow!("--namespace is only supported with --lang csharp"));
        }

        let module: ModuleDef = if let Some(paths) = &json_module {
            let DeserializeWrapper::<RawModuleDef>(module) = if let Some(path) = paths.first() {
                serde_json::from_slice(&fs::read(path)?)?
            } else {
                serde_json::from_reader(std::io::stdin().lock())?
            };
            module.try_into()?
        } else {
            let path = if let Some(path) = &run.wasm_file {
                println!("Skipping build. Instead we are inspecting {}", path.display());
                path.clone()
            } else if let Some(path) = &run.js_file {
                println!("Skipping build. Instead we are inspecting {}", path.display());
                path.clone()
            } else {
                let (path, _) =

View on GitHub (pinned to 524b4487d9)

Solutions

  1. Remove `--namespace` from the CLI invocation
  2. Move the namespace into the csharp target: `"namespace": "MyCo.MyApp"` in spacetime.json
  3. Generate the C# target separately: `spacetime generate --lang csharp --namespace MyCo.MyApp --database <db>`

Example fix

# before
spacetime generate --namespace MyCo.MyApp   # fails when any target is not csharp

# after — spacetime.json
{
  "generate": { "targets": [
    { "database": "mydb", "lang": "rust", "out-dir": "src/generated" },
    { "database": "mydb", "lang": "csharp", "namespace": "MyCo.MyApp", "out-dir": "module_bindings" }
  ] }
}

# then: spacetime generate --database mydb
Defensive patterns

Strategy: validation

Validate before calling

# Only add --namespace when every target being generated is csharp:
set -- $(jq -r '.generate.targets[]? | select((.database // "*") == "mydb") | .lang' spacetime.json)
for lang in "$@"; do
  [[ "$lang" == csharp ]] || { echo "--namespace skipped: target lang=$lang" >&2; NS_ARG=(); break; }
done
spacetime generate --database mydb "${NS_ARG[@]}"

Type guard

// Rust: only the csharp codegen accepts a namespace.
fn allows_namespace(lang: &str) -> bool {
    lang.eq_ignore_ascii_case("csharp")
}

Prevention

When it happens

Trigger: `spacetime generate --namespace MyCo.MyApp --lang typescript`; a multi-target spacetime.json containing rust and csharp targets invoked with the `--namespace` CLI flag.

Common situations: 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.

Related errors


AI-assisted analysis of clockworklabs/SpacetimeDB@524b4487d9 (2026-08-16). Data as JSON: /api/errors/534fd6fc863b2b47. Report an issue: GitHub.