oraios/serena · error · SolidLSPException

Failed to initialize C# language server for {self.repository

Error message

Failed to initialize C# language server for {self.repository_root_path}: {e}

What it means

Raised by _start_server when the LSP initialize request to the Roslyn language server throws. The server process started but failed to complete LSP initialization, so the server cannot be used for the repository at self.repository_root_path.

Source

Thrown at src/solidlsp/language_servers/csharp_language_server.py:673

        self.server.on_request("workspace/_roslyn_projectNeedsRestore", handle_project_needs_restore)

        log.info("Starting Microsoft.CodeAnalysis.LanguageServer process")

        try:
            self.server.start()
        except Exception as e:
            log.info(f"Failed to start language server process: {e}", logging.ERROR)
            raise SolidLSPException(f"Failed to start C# language server: {e}")

        # Send initialization
        initialize_params = self._create_initialize_params()

        log.info("Sending initialize request to language server")
        try:
            init_response = self.server.send.initialize(initialize_params)
            log.info(f"Received initialize response: {init_response}")
        except Exception as e:
            raise SolidLSPException(f"Failed to initialize C# language server for {self.repository_root_path}: {e}") from e

        # Apply diagnostic capabilities
        self._force_pull_diagnostics(init_response)

        # Verify required capabilities
        capabilities = init_response.get("capabilities", {})
        required_capabilities = [
            "textDocumentSync",
            "definitionProvider",
            "referencesProvider",
            "documentSymbolProvider",
        ]
        missing = [cap for cap in required_capabilities if cap not in capabilities]
        if missing:
            raise RuntimeError(
                f"Language server is missing required capabilities: {', '.join(missing)}. "
                "Initialization failed. Please ensure the correct version of Microsoft.CodeAnalysis.LanguageServer is installed and the .NET runtime is working."
            )

View on GitHub (pinned to 7fcbca7e62)

Solutions

  1. Read the wrapped exception {e} and language-server stderr logs for the underlying crash
  2. Ensure the .NET SDK required by your solution is installed and that the solution builds (`dotnet build`)
  3. Verify the repository contains a valid .sln/.csproj and that solutionPath/solution options passed to the server are correct
  4. Increase initialization timeout for large solutions and retry

Example fix

// before: server launched without solution info, initialize fails
// after: ensure solution is discoverable/valid
$ dotnet build MySolution.sln # confirm solution compiles
# then reconnect: CSharpLanguageServer(repo_root_with_sln)
Defensive patterns

Strategy: try-catch

Validate before calling

import subprocess

def solution_buildable(repo_root: str) -> bool:
    from pathlib import Path
    if not list(Path(repo_root).rglob("*.sln")) + list(Path(repo_root).rglob("*.csproj")):
        return False
    sln = next(Path(repo_root).rglob("*.sln"), None)
    if sln is None:
        return True
    return subprocess.run(["dotnet", "build", str(sln), "--nologo", "-v", "q"],
                          capture_output=True, timeout=600).returncode == 0

Type guard

def repo_has_csharp_project(repo_root: str) -> bool:
    from pathlib import Path
    root = Path(repo_root)
    return any(root.rglob("*.sln")) or any(root.rglob("*.csproj"))

Try / catch

try:
    ls._start_server()
except SolidLSPException as e:
    if str(e).startswith("Failed to initialize C# language server"):
        log.warning(f"LSP init failed for {ls.repository_root_path}: {e}; retrying once after checking dotnet build")
        solution_buildable(ls.repository_root_path)  # surface real build errors first
        ls._start_server()
    else:
        raise

Prevention

When it happens

Trigger: CSharpLanguageServer._start_server when self.server.send.initialize(initialize_params) raises — server crashed right after startup, rejected initialize params, timed out, or solution/solution-level options are invalid.

Common situations: Server process exiting early due to missing .NET components (e.g. missing xlfsvc/MSBuild workloads), invalid solution path or unsupported project type, mismatched LSP protocol/capabilities, or initialization timeout on very large solutions.

Related errors


AI-assisted analysis of oraios/serena@7fcbca7e62 (2026-08-29). Data as JSON: /api/errors/70d01bfc0ea10bdf. Report an issue: GitHub.