Emacs and C# LSP

Hi,

i am trying to setup emacs with, at this point, any lsp for C# (omnisharp, csharp-ls).
If i use lsp-install-server to install omnisharp, and try to start the lsp it just says: ¨Doing vfork: No such file or directory"

omnisharp-stderr is empty and lsp-log:

Command "semgrep lsp" is present on the path.
Found the following clients for /home/thomas/Projects/aoc/aoc_cs/Program.cs: (server-id semgrep-ls, priority -1), (server-id omnisharp, priority -1)
The following clients were selected based on priority: (server-id omnisharp, priority -1), (server-id semgrep-ls, priority -1)

If i use omnisharp or csharp-ls in my configuration.nix the lsps starts but they both have massive brainfarts!
using System is a useless import System.Integer not found and stuff like that…

I don´t know what to do…

Hi,

you could try running the LSP server just on the command line to see if the program works at all.

Are you using NixOS? If so, you may want to check out GitHub - Mic92/nix-ld: Run unpatched dynamic binaries on NixOS which also explains what issue you may be experiencing. Also if you’re on NixOS, why not try installing the LSP using nix, so it’s managed in your setup instead of imperatively in some random version that is downloaded by the lsp-mode Emacs package.

Hi t0m,

i am on nixos and i tried the version installed through nixos. It starts when i run it from the cli, but it gives weird errors, like Using System is an unused import or when i use variable it says for example “Predefind type System.Void is not defined or imported”

Here is a gist with lsp-log: lsp-log · GitHub

Here are some errors it throws: lsp error · GitHub

The problem is i got the same behavior with csharp-ls…

EDIT: here is what happends when run in the project folder from cli: omnisharp cli · GitHub

Hi Thomas,

I am a bit out of my depth with C#, tbh.

Are you using a nix dev shell with maybe direnv as well?
From using rust-analyzer with Nix and direnv I know that I would always have to match up the versions. E.g. I need to specify my dev shell to use rust-analyzer, cargo and rustc from the same nixpkgs because otherwise there may be miscompilations and weird error messages because rust-analyzer from my system environment may wrapped to use e.g. Rust 1.74 and my dev shell may still compile with Rust 1.71. That would cause incompatible objects to be generated, depending on which version was used to build a specific object in my build directory.

Maybe something similar applies for C# as well? Not really anything else that I could think of that could be helpful.