i'm try to learn signalr and this error i'm founded it.
Cannot read property 'chatHub' of undefined.
$(document).ready(function () {
var chat = $.connection.chatHub;
$.connection.hub.start();
});
and hub file is:
namespace TestSignalR.Web.Hubs
{
public class ChatHub : Microsoft.AspNet.SignalR.Hub
{
public void Send(string msg)
{
ChatData chat = new ChatData();
chat.Msg = msg;
chat.UserName = HttpContext.Current.User.Identity.Name;
chat.Date = "♣ at " + DateTime.Now.ToString("hh:mm tt");
Clients.All.broadCastMessage(chat);
}
}
}
I always seem to run into this problem due to how MVC tries to be helpful and renders the jquery bundle. Then when you try to add signalr in your view it will fail because you have to add jquery in beforehand, but jquery is then loaded again by the MVC bundle. This confuses stuff it seems and causes errors. You will probably have this section in your main layout page:
So if you add your scripts to the scripts section it should make signalr happy and work fine.
I had a problem with Firefox, in my case, I'm using https and in dev it does not exist, so I got the error because the exception for https was not registered. Just access the signalr server and add that.
I face the same problem after try this tutorial: https://docs.microsoft.com/en-us/aspnet/signalr/overview/getting-started/tutorial-getting-started-with-signalr
I recognize one instruction missing:
Probably missing this line in the
<HEAD>
of your document:Check you also have
And check, using Fiddler or Chrome Developer Tools that both files are loading and that the /hubs file contains what you expect it to contain in terms of hub definitions.
The solution for all those who had correct dll but even the solution is not working is that the function names casing gets changed.
Like my class name is TestAHub
But it is changed to testAHub.
You actually need to open this js "/signalr/hubs" to check the names.
Check you have app.MapSignalR(); on your Startup.cs file. See more on http://www.asp.net/signalr/overview/releases/upgrading-signalr-1x-projects-to-20.