Reputation: 184
Here is the screenshot of runtime project that contains signalR.
There is no hubs file generated. I am getting the most common javascript error That is also shown in picture. I searched and found many solutions but nothing seems to work. like changing reference src and etc. Here is how I am referencing the script files.
<script src="Scripts/jquery-3.3.1.min.js"></script>
<!--Reference the SignalR library. -->
<script src="Scripts/jquery.signalR-2.2.2.min.js"></script>
<!--Reference the autogenerated SignalR hub script. -->
<script src='<%: ResolveClientUrl("~/signalr/hubs") %>'></script>
Please advice something on this. The code is the sample code from microsoft docs. Tutorial: Getting Started with SignalR 2
EDIT1:
After a more research and changing some lines, Now hubs file is present, I can see there is no signalR JS file during runtime.and the error is -
0x800a139e - JavaScript runtime error: SignalR: SignalR is not loaded. Please ensure jquery.signalR-x.js is referenced before ~/signalr/js.
Upvotes: 0
Views: 737
Reputation: 184
Finally got the answer. I was trying every possible thing I got on internet and then one thing worked. and that was in this line [HubName("myHub")].. I had this name as [HubName("MyHub")] before and so the error.
[HubName("myHub")]
public class MyHub : Hub
{
// public static string constr = System.Configuration.ConfigurationManager.ConnectionStrings["CresijCamConnectionString"].ConnectionString;
public void Send(string name, string message)
{
// Call the broadcastMessage method to update clients.
Clients.All.broadcastMessage(name, message);
}
You need to define HubName same as you used in javascript so that there wont be any confusion in getting client.
var chat = $.connection.myHub;
Upvotes: 0