Skip to content

Commit 0763b5a

Browse files
committed
Fix invalid cast issue in omnisharp-roslyn by fixing LspHandlerDescriptor .ctor
The issue (apparently) is that LspHandlerDescriptor is constructed for DelegatingRequest that is registered in LanguageServerHost.cs (in omnisharp-roslyn) via .OnRequest(). The constructor attempts to resolve RPC return type based on what generic type is set on IRequest<T> that inherits DelegatingRequest. However DelegatingRequest implements both IRequest and IRequest<TResponse> and .LINQ query selects IRequest<MediatR.Unit> type as the return value -- while it should be IRequest<JToken>. Fixed by ordering implemented IRequest<> interfaces by generic param type and taking the first that is not MediatR.Unit -- only then use the MediatR.Unit version.
1 parent 81a38cc commit 0763b5a

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/Protocol/Shared/LspHandlerDescriptor.cs

+5-2
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,11 @@ public LspHandlerDescriptor(
6969
CapabilityType = capabilityType;
7070

7171
Response = @params?.GetInterfaces()
72-
.FirstOrDefault(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(IRequest<>))
73-
?.GetGenericArguments()[0] ?? typeDescriptor?.ResponseType ?? typeof(Unit);
72+
.Where(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(IRequest<>))
73+
.Select(x => x.GetGenericArguments()[0])
74+
.OrderBy(x => x == typeof(Unit))
75+
.FirstOrDefault()
76+
?? typeDescriptor?.ResponseType ?? typeof(Unit);
7477

7578
// If multiple are implemented this behavior is unknown
7679
CanBeResolvedHandlerType = handler.GetType().GetTypeInfo()

0 commit comments

Comments
 (0)