11
votes

I have a working SignalR application that allows me to connect multiple JavaScript clients and exchange data. When I tried to connect with a .NET client I get the following error:

An exception of type 'Microsoft.AspNet.SignalR.Client.HttpClientException' occurred in mscorlib.dll but was not handled in user code

Additional information: StatusCode: 500, ReasonPhrase: 'Internal Server Error', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:

{
  Transfer-Encoding: chunked
  X-SourceFiles: =?UTF-8?B?QzpcVXNlcnNcRGFycmVuXERlc2t0b3BcQ29uc29sZUFwcGxpY2F0aW9uMVxXZWJBcHBsaWNhdGlvbjFcc2lnbmFsclxuZWdvdGlhdGU=?=
  Cache-Control: private
  Date: Thu, 28 May 2015 09:13:06 GMT
  Server: Microsoft-IIS/8.0
  X-AspNet-Version: 4.0.30319
  X-Powered-By: ASP.NET
  Content-Type: text/html; charset=utf-8
}

To remove as many variables as possible I copied the Hub into an brand new web application and copied the .NET client code into a console application. I still get the same exception. Here is my client code:

Dim hubConnection As HubConnection
Dim chatHubProxy As IHubProxy

Public Async Sub RunTest()
    System.Net.ServicePointManager.DefaultConnectionLimit = 10

    hubConnection = New HubConnection("http://localhost:64400")
    hubConnection.Credentials = Net.CredentialCache.DefaultCredentials
    hubConnection.TraceLevel = TraceLevels.All
    hubConnection.TraceWriter = Console.Out

    chatHubProxy = hubConnection.CreateHubProxy("Chat")

    AddHandler hubConnection.StateChanged, Sub(stateChange) Console.WriteLine("[" & DateTime.Now & "]: " & stateChange.OldState.ToString() & " =>  " & stateChange.NewState.ToString() & " " & hubConnection.ConnectionId)

    chatHubProxy.On(Of String, String)("ReceiveMessage", Sub(from, message) Console.WriteLine(message))
    Await hubConnection.Start()
End Sub

Here is the console output:

09:21:54.3952161 - null - ChangeState(Disconnected, Connecting)
[28/05/2015 10:21:54]: Disconnected =>  Connecting
[28/05/2015 10:21:56]: Connecting =>  Disconnected
09:21:56.8448452 - null - Disconnected
09:21:56.8458461 - null - Transport.Dispose()
09:21:56.8468465 - null - Closed

And here is my hub code:

public class ChatHub : Hub
{
    public void SendMessage(string name, string message)
    {
        Clients.All.ReceiveMessage(name, message);
    }
}
5
Try to turn on SignalR tracing on server. Hopefully SignalR will log the error...Michal Levý

5 Answers

19
votes

This turned out to be a trivial mistake, but the error message was so useless I'm sure others will be stumped by the same issue. The name of the hub was wrong. I used "Chat" when I should have used "ChatHub".

If the exception had been 404, or "Hub not found" or something like that it would have been an easy fix rather than a couple of wasted hours!

7
votes

@Michael Tiller's comment in @Darren's answer turned out to be the solution for my problem, so I think it's fair to make this into its own answer:

Changing the Hub class to public solved my problem. I followed an example and missed the text that said to create a PUBLIC class that inherits from Hub, and when adding a new class in Visual Studio, by default it creates it as

class TestHub
{
}

...which is technically internal (see here). More careful reading on my part would have prevented this, but in case someone else got in too big of a hurry like I did... :)

1
votes

Real issue was resolved but i think it's important to realise that SignalR server returning status 500 (Internal Server Error) (not very informative error indeed) is security feature.

If you need more information on server errors, you can do following:

1) Enable tracing on server

and\or

2) Enable detailed exception messages send to client (don't do that in production!):

SignalR 1.x: RouteTable.Routes.MapHubs(new HubConfiguration { EnableDetailedErrors = true });

SignalR 2.x

public void Configuration(IAppBuilder app)
{
        var hubConfiguration = new HubConfiguration
        {
#if DEBUG
            EnableDetailedErrors = true
#else
            EnableDetailedErrors = false
#endif
        };

        app.MapSignalR(hubConfiguration);
}
0
votes

I was doing similar trivial mistake took few hours to figure it out.

[HubName("Hostsync")] // Missed to add this attribute in Hub of SignalR Self Host
public class ChatHub : Hub
{

}

But i was trying to connect by defining the proxy name in Client.

HostProxyName = "Hostsync";

Just make sure there is no such kind of mistakes. Since you will not be getting the exact detailed exception during the connection establishment.

The following link helped me to address few things

Stackoverflow Question Answer Link

Hope this helps.,

0
votes

I had the same issue. I found out that the SignalR Jquery extension version was older than the referenced SignalR library. I corrected the script version and problem solved. If you have recently upgraded the SignalR to newer version, you would probably face the same issue like me.