csharp-language-server-protocol icon indicating copy to clipboard operation
csharp-language-server-protocol copied to clipboard

Server unhandled exception when trying to parse `traceparent` property in `Initialize` message. Client (VS2019) becomes unresponsive.

Open sstublic opened this issue 4 years ago • 1 comments

I'm not sure if I'm missing something obvious, but my scenario is as follows:

Running OmniSharp LanguageServer 0.19.2 and VS 2019 version 16.10.3. When Initialize message is sent, the server reports an error:

OmniSharp.Extensions.JsonRpc.InputProcessingException: There was an error processing input the contents of the buffer were ''
 ---> System.InvalidCastException: Cannot cast Newtonsoft.Json.Linq.JProperty to Newtonsoft.Json.Linq.JToken.
   at Newtonsoft.Json.Linq.Extensions.Convert[T,U](T token)
   at Newtonsoft.Json.Linq.Extensions.Value[T,U](IEnumerable`1 value)
   at Newtonsoft.Json.Linq.Extensions.Value[U](IEnumerable`1 value)
   at OmniSharp.Extensions.JsonRpc.Receiver.GetRenor(JToken object)
   at OmniSharp.Extensions.JsonRpc.Receiver.GetRequests(JToken container)
   at OmniSharp.Extensions.LanguageServer.Server.LspServerReceiver.GetRequests(JToken container)
   at OmniSharp.Extensions.JsonRpc.InputHandler.HandleRequest(ReadOnlySequence`1& request)
   at OmniSharp.Extensions.JsonRpc.InputHandler.ProcessInputStream(CancellationToken cancellationToken)
   --- End of inner exception stack trace ---

After this error VS2019 becomes unresponsive and server doesn't log additional events.

The culprit seems to be the line https://github.com/OmniSharp/csharp-language-server-protocol/blob/f5c9691db0540c6c5870d3eba4ad4bd538852f25/src/JsonRpc/Receiver.cs#L116

VS2019 will provide traceparent value but the above line will always fail with reported exception if there is any value in the property.

It seems to me that line should read:

TraceParent = properties["traceparent"].FirstOrDefault()?.Value.Value<string>()

instead of

TraceParent = properties["traceparent"].FirstOrDefault()?.Value<string>()

However, this would mean that with addition of traceparent/tracestate property parsing NO clients which actually send those values would work at all with OmniSharp 0.19.2. That seems unlikely.

Any ideas what I'm missing?

Thanks!

sstublic avatar Jul 01 '21 18:07 sstublic

Fixed by: https://github.com/OmniSharp/csharp-language-server-protocol/pull/638

NTaylorMullen avatar Aug 18 '21 19:08 NTaylorMullen