windmill-labs/windmill · critical

Error setting c# as language: {e}

Error message

Error setting c# as language: {e}

What it means

This error comes from parse_csharp_sig_meta when the tree-sitter parser refuses to load the C# grammar via parser.set_language(). It wraps the underlying tree_sitter::LanguageError, which normally indicates a version mismatch between the tree_sitter runtime crate and the tree-sitter-c-sharp grammar crate, or a corrupted/incompatible grammar object. In practice it is almost never caused by user script content — it fires before any code is parsed.

Source

Thrown at backend/parsers/windmill-parser-csharp/src/lib.rs:32

    pub is_async: bool,
    pub is_public: bool,
    pub returns_void: bool,
    pub class_name: Option<String>,
    pub main_sig: MainArgSignature,
}

fn csharp_param_default_value<'a>(def: Node<'a>, code: &str) -> Option<serde_json::Value> {
    def.utf8_text(code.as_bytes())
        .ok()
        .and_then(|content| serde_json::from_str(content).ok())
}

pub fn parse_csharp_sig_meta(code: &str) -> anyhow::Result<CsharpMainSigMeta> {
    let mut parser = tree_sitter::Parser::new();
    let language = tree_sitter_c_sharp::LANGUAGE;
    parser
        .set_language(&language.into())
        .map_err(|e| anyhow!("Error setting c# as language: {e}"))?;

    // Parse code
    let tree = parser.parse(code, None).expect("Failed to parse code");
    let root_node = tree.root_node();

    // Traverse the AST to find the Main method signature
    let main_sig = find_main_signature(root_node, code);
    let auto_kind = if main_sig.is_none() {
        Some("lib".to_string())
    } else {
        None
    };
    let mut is_async = false;
    let mut is_public = false;
    let mut returns_void = false;
    let mut class_name = None;

    let mut args = vec![];

View on GitHub (pinned to e474e8803c)

Solutions

  1. Run cargo update -p tree-sitter-c-sharp and cargo update -p tree-sitter together so both resolve to ABI-compatible versions, then cargo clean -p tree-sitter -p tree-sitter-c-sharp and rebuild
  2. Check the tree-sitter LANGUAGE_VERSION/MIN_LANGUAGE_VERSION constants against the grammar crate version and pin a known-good pair in Cargo.toml
  3. Delete stale target artifacts (cargo clean) and rebuild — ABI mismatches often persist via incremental caches
  4. If building for wasm, confirm the grammar crate is compiled with the wasm-compatible feature set

Example fix

// before (Cargo.toml)
tree-sitter = "0.22"
tree-sitter-c-sharp = "0.20"
// after (aligned versions)
tree-sitter = "0.22"
tree-sitter-c-sharp = "0.22"
Defensive patterns

Strategy: try-catch

Validate before calling

// No user-side pre-check: the failure is environmental (crate ABI), not input-dependent.
// CI check that catches it before deploy:
// cargo test -p windmill-parser-csharp

Try / catch

match parse_csharp_sig_meta(code) {
    Ok(meta) => meta,
    Err(e) if e.to_string().contains("Error setting c# as language") => {
        // dependency/ABI problem: report as build-environment issue, not script issue
        bail!("parser build environment broken (tree-sitter ABI): {e}")
    }
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: Calling parse_csharp_sig_meta (directly or via parse_csharp_signature) when the compiled tree-sitter runtime ABI version does not match the one tree-sitter-c-sharp was generated against, or when the Parser fails to accept the LANGUAGE binary. Any script-signature extraction on a C# script hits this path.

Common situations: A Cargo.lock drift or partial upgrade where tree_sitter was bumped but tree-sitter-c-sharp was not (or vice versa); building with mismatched feature flags across a workspace; mixing wasm and native builds of the grammar; stale build artifacts after a toolchain update.

Related errors


AI-assisted analysis of windmill-labs/windmill@e474e8803c (2026-09-03). Data as JSON: /api/errors/a5c4adb6674e8783. Report an issue: GitHub.