Using generic methods on SignalR Hub

孤街浪徒 提交于 2019-12-23 12:54:28

问题


I'm creating a Hub class for my SignalR server and wanted to use a generic method which will save me from tons of lines of code. But SignalR is giving me errors when I try to Invoke the server code below from a Xamarin.iOS client which also in C#.

Server Code

public List<T> SendDataToClient<T>() where T : BusinessEntityBase
{
   return SomeDBManager.GetItems<T>();
}

Client Code

var list = await hubProxy.Invoke<List<Article>>("SendDataToClient");

Am I doing something wrong here or is it just impossible to use generic methods in SignalR Hubs?


回答1:


You cannot invoke generic methods from SignalR clients. You'll notice that if you run signalr ghp /path:myassembly.dll against the dll containing the hub with the generic SendDataToClient method, you'll get the following error:

System.ArgumentException: Method System.Collections.Generic.List`1[T] SendDataToClient[T]() is a generic method definition

It's easier to see this error when using the signalr ghp command to generate a JavaScript hub proxy file, but this is the same error that is occurring on the server when you try to invoke SendDataToClient.



来源:https://stackoverflow.com/questions/21759577/using-generic-methods-on-signalr-hub

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!