42

Server:

public void AddLine(string line)
{
    Clients.Others.addLine(line);
}

.NET Client:

await rtHubProxy.Invoke("AddLine", "lineInfo");

Exception:

InvalidOperationException: There was an error invoking Hub method 'xxx.AddLine'.

Actually, I was trying to invoke the method with complex object, only to find the exception. Therefore, I changed the type of the parameter and left the AddLine() body blank for debugging purposes, which weirdly enough, it still threw the same exception.

I also have another SignalR invocation on the client-side, just several lines above, which runs responsively without error. The corresponding server-side code as follows:

public void Hello(string text)
{
    Clients.All.hello(text);
}

Could anyone find out where I've got wrong? I've been debugging for more than 4 hours and still cannot find the undoing even after I simplified the code.

(Spelling strictly checked, no mismatch.)

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Isilmë O.
  • 1,668
  • 3
  • 23
  • 35

2 Answers2

81

Clearly you have some problems on the server side. But to find out what's the problem you need to see a detailed error. For security reasons SignalR doesn't give you a detailed error by default. But you can edit your code to get the detailed error.

First you need to add this code to the Startup.cs:

var hubConfiguration = new HubConfiguration();
hubConfiguration.EnableDetailedErrors = true;
app.MapSignalR(hubConfiguration);

Then to show the error on the client side you need to add this code to your project:

$.connection.hub.error(function (error) {
    console.log('SignalR error:', error)
});

As simple as that and you're good to go.

Sometimes you don't even get to the client part to see the error. But by doing the first part you'll enable the Detailed Error and you can see the errors on the SignalR response. You just need a tool like Chrome Browser Web Developer Tool which gives you the Network part of the operation where all the data transfer status are logged. you can check the SignalR errors there. The information on the log will be very detailed and helpful.

This is a sample debug with Chrome Browser for people who what to see SignalR errors through Chrome debug tool:

Download Full Image Size

This is for people who want to debug the ajax response through Chrome Browser

Let me know if you have other problems regarding that.

For extra information go to: SignalR Errors

Hirad Nikoo
  • 1,599
  • 16
  • 26
  • 1
    Thanks for your answer! Actually I've enabled the option, but still find the exception message quite brief most of the times. I guess the problem lies in that the server-side code was not refreshed and sometimes even not running when I debug the SignalR. – Isilmë O. Dec 21 '13 at 07:13
  • Could you please give me the exception message? – Hirad Nikoo Dec 21 '13 at 07:45
  • Please see the [above image](http://goo.gl/GUozcF) for debugging instructions if you feel needed. [Download Full Image Size](http://goo.gl/GUozcF) – Hirad Nikoo Dec 21 '13 at 08:16
  • The exception message was stated in the title, nothing more. If you debug it in VS, all you get will be the same. I'm wondering if there is any helper for developing dynamic SignalR project. PS: Ow, thanks for the tip! I turned the error messages in Chrome inside out only to forget Chrome had got that feature that I didn't enable in the settings. :) – Isilmë O. Dec 21 '13 at 11:41
  • 1
    @HiredNikoo, your image link is dead, and you should not redirect them to external websites, just upload it here and share that link. – CularBytes Oct 13 '16 at 12:58
  • Just an addition: My problem with the same error was calling method that had optional parameters WITHOUT them. As soon as I provided ALL of the parameters (including the optional ones) it all started to work. – podvlada Oct 21 '16 at 13:07
  • 1
    @Hirad Nikoo, thank you for your answer. I was wondering why exception message was not showing details in signalR response. According to your comment I went to startup.cs class and found out "hubConfiguration.EnableDetailedErrors" was set to "false". I just set it to "true" for debugging purpose and then set it back to "false". That saved my day. – Nadim Hossain Sonet Oct 25 '17 at 05:21
  • @NadimHossainSonet Glad to be of help :) – Hirad Nikoo Dec 26 '17 at 06:16
  • Hi - the image appears to be just a thumbnail :( – Ian Grainger Sep 07 '18 at 10:17
3

OK, after 2 hours and half's rocky debugging, I finally found out the truth, realizing that weiredly, however I changed my server-side code, the undercover mechanism or functionalities didn't somehow get synchronized until I accidently rebuilt the project and waited the IIS Express to warm-up again.

It's not SignalR's fault, but Visual Studio's I think. Every time I make some changes to the Hub class, I have to rebuild the server-side project. That's it. I have to say, it really aches, though I don't know why this should happen - Maybe that's because my solution consists of WinRT and ASP.NET project that don't get along well? I don't know.

FYI, I will attach a link to a post, in which a similar "rebuild" issue did happen to someone else.

http://forum.kooboo.com/yaf_postst2250_How-to-use-SignalR-in-a-Module.aspx

And the workaround for now is more than simple - just go and REBUILD.

Isilmë O.
  • 1,668
  • 3
  • 23
  • 35