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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With