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?

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top