Suprabhat Biswal
Suprabhat Biswal

Reputation: 3216

SignalR Error: signalR(...).starting(...).sending is not a function

I'm learning basics of implementing SignalR from beside link Asp.Net Signal MVC4. Just like the tutorial suggested I have implemented a demo application but I am not able to resolve following error.

Uncaught TypeError: signalR(...).starting(...).sending is not a function

This is what I have tried so far.

Prerequisite:

  1. Microsoft.AspNet.SignalR
  2. WebAPIDoodle.SignalR

Hub

namespace SignalRChat.Hubs
{        
    public class ChatHub : Hub
    {
        public void Send( string name, string message )
        {
            Clients.All.addNewMessageToPage( name, message );
        }
    }
}

Owin Startup

[assembly: OwinStartup( typeof( SignalRChat.Startup ) )]

namespace SignalRChat
{
    public class Startup
    {
        public void Configuration( IAppBuilder app )
        {
            app.MapSignalR();
        }
    }
}

Controller

public ActionResult Chat()
{
    return View();
}

View (Chat)

@{
    ViewBag.Title = "Chat";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>Chat</h2>
<div class="container">
    <input type="text" id="message" />
    <input type="button" id="sendmessage" value="Send" />
    <input type="hidden" id="displayname" />
    <ul id="discussion"></ul>
</div>
@section scripts {
    <!--Script references. -->
    <!--The jQuery library is required and is referenced by default in _Layout.cshtml. -->
    <!--Reference the SignalR library. -->
    @*<script src="~/Scripts/jquery.signalR-2.1.0.min.js"></script>*@
    <script src="http://ajax.aspnetcdn.com/ajax/signalr/jquery.signalr-2.0.0.min.js"></script>
    <!--Reference the autogenerated SignalR hub script. -->
    <script src="~/signalr/hubs"></script>
    <!--SignalR script to update the chat page and send messages.-->
    <script type="text/javascript">
        $(function () {

            var connection = $.connection('/echo');
            console.log(connection);
            // Reference the auto-generated proxy for the hub.
            var chat = $.connection.chatHub;
            // Create a function that the hub can call back to display messages.
            chat.client.addNewMessageToPage = function (name, message) {
                // Add the message to the page.
                $('#discussion').append('<li><strong>' + htmlEncode(name)
                    + '</strong>: ' + htmlEncode(message) + '</li>');
            };
            // Get the user name and store it to prepend to messages.
            $('#displayname').val(prompt('Enter your name:', ''));
            // Set initial focus to message input box.
            $('#message').focus();
            // Start the connection.
            $.connection.hub.start().done(function () {
                $('#sendmessage').click(function () {
                    // Call the Send method on the hub.
                    chat.server.send($('#displayname').val(), $('#message').val());
                    // Clear text box and reset focus for next comment.
                    $('#message').val('').focus();
                });
            });
        });
        // This optional function html-encodes messages for display in the page.
        function htmlEncode(value) {
            var encodedValue = $('<div />').text(value).html();
            return encodedValue;
        }
    </script>
}

I not able to resolve following error. Is there anything I'm missing here because I have installed all required files and using latest Jquery. I tried using lower version of signalR but still same issue persist.

Here, the snapshot of developer console with list of error.

enter image description here

Source of error

enter image description here

Upvotes: 3

Views: 3118

Answers (2)

Minion Dương
Minion Dương

Reputation: 1

instead of using 'sending' you should use 'send' because in the file 'charthub.cs' you have declared 'public void send (...)'javascript myhub.cs

Upvotes: 0

Suprabhat Biswal
Suprabhat Biswal

Reputation: 3216

I have finally sorted out the exception the one I have mentioned in my question. Actually I have unnecessarily installed WebAPIDoodle.SignalR dll. I have dumped this project and started with a fresh one as soon a the new project setup completes I went to package console manager and one by one updated following dll.

  1. Microsoft.AspNet.SignalR
  2. Microsoft.Owin
  3. Microsoft.Owin.Security
  4. Microsoft.Owin.Host.SystemWeb

Rest process was same as the tutorial suggested creating a owin startup class and a hub class. Doing this much the application worked perfectly just like mentioned in the tutorial. What I do notice was both project signalr autogenereted javascript were different I guess this was because previously I have unnecessarily installed WebAPIDoodle.SignalR dll which gave me a different javascript.

Upvotes: 1

Related Questions