Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SignalR strongly typed hub TypeLoadException

I'm encountering a TypeLoadException when I use a strongly typed hub. My interface is:

public interface IClientCallback
{
    void callback<T>(T msg, string eventType);
    void test(string msg, string eventType); 
}

All the methods are inside a single interface, and the interface does not inherit from any other interface.

My Hub class is:

public class ServiceHub : Hub<IClientCallback>
{
    public static readonly string ServiceHubName = "ServiceHub";

    public void Register(string name, string eventType)
    {
        Clients.All.test("hello", "world");
    }
}

When I use my client app to invoke the Register method on the hub, on the Hub application I receive an exception when it is at Clients.All.test(...):

TypeLoadException Method 'callback' in type 'Microsoft.AspNet.SignalR.Hubs.TypedClientBuilder.IClientCallbackImpl' from assembly 'Microsoft.AspNet.SignalR.Hubs.TypedClientBuilder, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' does not have an implementation.

I haven't been able to narrow down what exactly is causing this exception to be thrown. A little help or suggesting would be greatly appreciated.

like image 512
user7702 Avatar asked Nov 14 '15 01:11

user7702


1 Answers

It took couple hours of debugging to work out that the problem is in generic method definition. It seems like it simply doesn't supported.

So as a workaround it's possible to change the type of msg parameter to object and make callback method not generic. After this change everything should be working.

I wish Microsoft at least would add a warning about this limitation to the documentation.

like image 159
Roman Koliada Avatar answered Oct 06 '22 00:10

Roman Koliada