Learning SignalR: Unable to get property ‘client’ of undefined or null reference

One of the most common exceptions you will hit when you first started with a SignalR chat program could look like the following:

Unhandled exception at line 78, column 13 in http://localhost:53632/home/chat

0x800a138f - JavaScript runtime error: Unable to get property 'client' of undefined or null reference


This is mostly like caused by the fact that your Hub class name and your javascript probably does not match. It is case sensitive. By default, SignalR runtime uses camel casing of the Hub class name.

For example, if your hub class looks like the following: 

   1: public class MyChatHub : Hub 
   2: { 
   3:     public void Send(string name, string message) 
   4:     { 
   5:         Clients.All.broadcastMyMessage(name, message); 
   6:     } 
   7: }

And the proxy referenced in your HtmlPage1.html might look like the following:

   1: // Declare a proxy to reference the hub.  
   2: var chat = $.connection.MyChatHub;

Now this does not work since camel casing means that you need to use "myChatHub" instead. so to fix it, you can modify your client side page to use the correct casing.

   1: // Declare a proxy to reference the hub.  
   2: var chat = $.connection.myChatHub;

Now if you would like to override this default behavior, you could add the HubName attribute to your MyChatHub class. SignalR runtime will use your name as it is, in whatever casing you like, as the name of the proxy.

   1: [HubName("MyChatHub")] 
   2: public class MyChatHub : Hub 
   3: { 
   4:     // omit the method here for simplicity 
   5: }


Hope this helps.

Comments (5)

  1. Ahmed Khaja says:

    Try adding reference like below to your class attribute


  2. Ahmed Khaja says:

    I got this client undefined error and adding the attribute to the HUB class


    and adding the below line in global.asax on application_start solved the client undefined problem, I hope this will help

    protected void Application_Start(object sender, EventArgs e)




  3. Jon says:

    Currently bowing down in praise of this post for fixing what promised to be a day wasting problem

  4. Gowtham says:

    Thanks Man u saved my day. it worked

  5. adjin says:

    it is nice,I like it.


Skip to main content