Search code examples
c#language-server-protocol

C# Language Client - TypeLoadException


I aim to implement a simple WPF application (.NET Framework 4.8) to host a text editor.

This text editor should act as a Language Client. The Language Server runs as an external application based on a custom DSL.

The issue is on the client side: while looking for ways to implement it in C#, I found the Omnisharp.Extensions.LanguageProtocol NuGet package, that seemed to fit my needs perfectly.

However, looking through the GitHub repository and browsing for tutorials/instructions on how to create a LanguageClient, I haven't found anything that works to get me started.

I tried to create the LanguageClient as follow

Process process = new() { StartInfo = info };
process.Start();

LanguageClientOptions options = new();
options.WithInput(process.StandardOutput.BaseStream)
    .WithOutput(process.StandardInput.BaseStream);

_client = LanguageClient.Create(options);

CancellationTokenSource cts = new();

await _client.Initialize(cts.Token);

Based on How to connect with c# language server client to language server But as soon as I reached the LanguageClient.Create method, it throws the following exception:

System.TypeLoadException: 'Method 'Handle' in type 'OmniSharp.Extensions.LanguageServer.Protocol.Client.WorkDone.LanguageClientWorkDoneManager' from assembly 'OmniSharp.Extensions.LanguageProtocol, Version=0.19.0.0, Culture=neutral, PublicKeyToken=6d868dff454e6022' does not have an implementation.'

Solution

  • The issue was related to version missmatches in the imported NuGet packages: after importing the Omnisharp.Extensions.LanguageClient, I updated all the packages through the NuGet Package Manager UI.

    A clean import of the package solved the problem.