{"record":{"id":"70d01bfc0ea10bdf","repo":"oraios/serena","slug":"failed-to-initialize-c-language-server-for-self","errorCode":null,"errorMessage":"Failed to initialize C# language server for {self.repository_root_path}: {e}","messagePattern":"Failed to initialize C# language server for (.+?): (.+?)","errorType":"exception","errorClass":"SolidLSPException","httpStatus":null,"severity":"error","filePath":"src/solidlsp/language_servers/csharp_language_server.py","lineNumber":673,"sourceCode":"        self.server.on_request(\"workspace/_roslyn_projectNeedsRestore\", handle_project_needs_restore)\n\n        log.info(\"Starting Microsoft.CodeAnalysis.LanguageServer process\")\n\n        try:\n            self.server.start()\n        except Exception as e:\n            log.info(f\"Failed to start language server process: {e}\", logging.ERROR)\n            raise SolidLSPException(f\"Failed to start C# language server: {e}\")\n\n        # Send initialization\n        initialize_params = self._create_initialize_params()\n\n        log.info(\"Sending initialize request to language server\")\n        try:\n            init_response = self.server.send.initialize(initialize_params)\n            log.info(f\"Received initialize response: {init_response}\")\n        except Exception as e:\n            raise SolidLSPException(f\"Failed to initialize C# language server for {self.repository_root_path}: {e}\") from e\n\n        # Apply diagnostic capabilities\n        self._force_pull_diagnostics(init_response)\n\n        # Verify required capabilities\n        capabilities = init_response.get(\"capabilities\", {})\n        required_capabilities = [\n            \"textDocumentSync\",\n            \"definitionProvider\",\n            \"referencesProvider\",\n            \"documentSymbolProvider\",\n        ]\n        missing = [cap for cap in required_capabilities if cap not in capabilities]\n        if missing:\n            raise RuntimeError(\n                f\"Language server is missing required capabilities: {', '.join(missing)}. \"\n                \"Initialization failed. Please ensure the correct version of Microsoft.CodeAnalysis.LanguageServer is installed and the .NET runtime is working.\"\n            )","sourceCodeStart":655,"sourceCodeEnd":691,"githubUrl":"https://github.com/oraios/serena/blob/7fcbca7e62555ec2287ddb2f083caee805848ea6/src/solidlsp/language_servers/csharp_language_server.py#L655-L691","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Read the wrapped exception {e} and language-server stderr logs for the underlying crash","Ensure the .NET SDK required by your solution is installed and that the solution builds (`dotnet build`)","Verify the repository contains a valid .sln/.csproj and that solutionPath/solution options passed to the server are correct","Increase initialization timeout for large solutions and retry"],"exampleFix":"// before: server launched without solution info, initialize fails\n// after: ensure solution is discoverable/valid\n$ dotnet build MySolution.sln # confirm solution compiles\n# then reconnect: CSharpLanguageServer(repo_root_with_sln)","handlingStrategy":"try-catch","validationCode":"import subprocess\n\ndef solution_buildable(repo_root: str) -> bool:\n    from pathlib import Path\n    if not list(Path(repo_root).rglob(\"*.sln\")) + list(Path(repo_root).rglob(\"*.csproj\")):\n        return False\n    sln = next(Path(repo_root).rglob(\"*.sln\"), None)\n    if sln is None:\n        return True\n    return subprocess.run([\"dotnet\", \"build\", str(sln), \"--nologo\", \"-v\", \"q\"],\n                          capture_output=True, timeout=600).returncode == 0\n","typeGuard":"def repo_has_csharp_project(repo_root: str) -> bool:\n    from pathlib import Path\n    root = Path(repo_root)\n    return any(root.rglob(\"*.sln\")) or any(root.rglob(\"*.csproj\"))\n","tryCatchPattern":"try:\n    ls._start_server()\nexcept SolidLSPException as e:\n    if str(e).startswith(\"Failed to initialize C# language server\"):\n        log.warning(f\"LSP init failed for {ls.repository_root_path}: {e}; retrying once after checking dotnet build\")\n        solution_buildable(ls.repository_root_path)  # surface real build errors first\n        ls._start_server()\n    else:\n        raise\n","preventionTips":["Make sure the solution builds with `dotnet build` before starting the language server","Install all required .NET SDKs/workloads used by the solution","Give the initialize step a generous timeout for large solutions","Capture language-server stderr/stdout logs to diagnose init rejections quickly"],"tags":["csharp","roslyn","lsp-initialization","timeout"],"backgroundTag":"lsp-initialization-failed","analyzedSha":"7fcbca7e62555ec2287ddb2f083caee805848ea6","analyzedAt":"2026-08-29T00:04:09.619Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}