Using common methods in a SignalR hub

I am creating a Hub class for my SignalR server and wanted to use a generic method that will save me a lot of lines of code. But SignalR gives me errors when I try to call the server code below from the Xamarin.iOS client, which is 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 common methods in SignalR hubs?

+4
generics c # signalr signalr-hub signalr.client
source share
1 answer

You cannot call generic methods from SignalR clients. You will notice that if you run signalr ghp /path:myassembly.dll against a DLL containing a hub using the common SendDataToClient method, you will receive the following error:

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

It is easier to see this error when using the signalr ghp command to create a proxy file for the JavaScript hub house, but this is the same error that occurs on the server when trying to call SendDataToClient.

+3
source share

All Articles