SignalR Javascript Client Error: Dynamic file not generated

南楼画角 提交于 2019-12-24 23:01:26

问题


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.


回答1:


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;



来源:https://stackoverflow.com/questions/52254049/signalr-javascript-client-error-dynamic-file-not-generated

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!