[BUG] LSP: Roslyn language server crashes with BadRpcHeaderException on Windows (\r\n header issue)

Resolved 💬 2 comments Opened Mar 12, 2026 by mike-echo-oscar-whiskey Closed Apr 12, 2026

Bug Description

The LSP tool fails with [Tool result missing due to internal error] when using roslyn-language-server (Microsoft's Roslyn LSP) on Windows. The root cause is a BadRpcHeaderException — the LSP client appears to send headers with \n line endings instead of the \r\n required by the LSP/JSON-RPC specification.

Steps to Reproduce

  1. Install the Roslyn language server as a .NET global tool:

``bash
dotnet tool install --global Microsoft.CodeAnalysis.LanguageServer
``

  1. Configure .lsp.json in the project root:

``json
{
"csharp": {
"command": "roslyn-language-server.cmd",
"args": ["--stdio", "--autoLoadProjects", "--logLevel", "Information"],
"transport": "stdio",
"extensionToLanguage": {
".cs": "csharp",
".csx": "csharp"
},
"initializationOptions": {},
"settings": {},
"startupTimeout": 120000
}
}
``

  1. Use any LSP operation on a .cs file:

``
LSP documentSymbol / hover / goToDefinition → [Tool result missing due to internal error]
``

Root Cause

Manual testing confirms the server starts but crashes immediately on the first message:

Content-Length: 116

{"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":"[Program] Language server initialized"}}
Unhandled exception. StreamJsonRpc.BadRpcHeaderException: Header does not end with expected \r\n character sequence: ...
   at StreamJsonRpc.HeaderDelimitedMessageHandler.ReadHeadersAsync(CancellationToken cancellationToken)
   at StreamJsonRpc.HeaderDelimitedMessageHandler.ReadCoreAsync(CancellationToken cancellationToken)

The LSP specification requires \r\n as header delimiters. The StreamJsonRpc library used by Roslyn enforces this strictly.

Environment

  • OS: Windows 11 Enterprise (10.0.22631)
  • Claude Code: Latest (via Anthropic API)
  • Language Server: roslyn-language-server v5.5.0 (Microsoft.CodeAnalysis.LanguageServer)
  • Shell: bash on Windows

Expected Behavior

LSP operations (hover, goToDefinition, documentSymbol, etc.) should work with the Roslyn language server.

Actual Behavior

All LSP operations return [Tool result missing due to internal error].

Related Issues

  • #16360 — Missing protocol handlers with csharp-ls (different server, different root cause)
  • #15914 — .cmd extension not found on Windows (different root cause — server discovery vs. protocol)

Suggested Fix

Ensure the LSP client sends \r\n line endings in JSON-RPC headers per the LSP specification §Header Part. This is likely a single-line fix in the header serialization code.

View original on GitHub ↗

This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗