question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SignalR client library needs better logging/access to underlying message data

See original GitHub issue

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

I made a silly mistake today that took me some time to debug because there appears to be no easy way to access the underlying messages sent by SignalR as plaintext.

I have a method where I added a cancellationTokenSource as such.

using (var cancelToken = new CancellationTokenSource(timeoutMS))
{
     return clientProxy.InvokeAsync<T>(methodName, request, cancelToken);
}

You might already be able to spot the problem (cancelToken should be cancelToken.Token) I had forgotten about this simple change I made and suddenly started getting the error:

Error reading JSON. ‘{’ is invalid after a value. Expected either ‘,’, ‘}’, or ‘]’. LineNumber: 0 | BytePositionInLine: 98.

I tried to enable detailed logging by adding trace for logging messages.

var conn = new HubConnectionBuilder()
.ConfigureLogging(logging =>
{
    logging.SetMinimumLevel(LogLevel.Trace);
});

Yet unfortunately I received no further details other than the message above.

In the end I needed to implement my own custom IHubProtocol by duplicating JsonHubProtocol which finally revealed the real error to me which was:

{"type":1,"invocationId":"9","target":"blahblah","arguments":[{blahblah}{"type":7,"error":"Connection closed with an error. NotSupportedException: Serialization and deserialization of 'System.IntPtr' instances are not supported. Path: $.Token.WaitHandle.Handle.","allowReconnect":true}

Describe the solution you’d like

I believe inside JsonHubProtocol -> ParseMessage on the error condition the entire message payload should be shown to the user or at least if tracing is turned on this should be the behaviour.

It should not be this difficult to find out what happened to cause deserialisation to fail.

Additional context

In summary, there should be more information when an error condition occurs deep inside the protocol.

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
BrennanConroycommented, Oct 11, 2022

Looking at this more closely, you’re hitting the issue described in https://github.com/dotnet/aspnetcore/issues/13651#issuecomment-527625710. As noted in the comment, there is a log on the server side that will have the nicer Json error message (it’s Error level now) that would have pointed you to the issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Logging and diagnostics in ASP.NET Core SignalR
SignalR uses two logger categories: Microsoft.AspNetCore.SignalR : For logs related to Hub Protocols, activating Hubs, invoking methods, and ...
Read more >
aspnetcore
SignalR client library needs better logging/access to underlying message data. help wantedarea-signalr. Created 10 months ago. Updated 10 months ago.
Read more >
What are the correct libraries to connect a SignalR client ...
Sounds good. I found SignalR Core client library and created a .Net Standard class to act as my SignalR client class. I tried...
Read more >
ASP.NET Core SignalR Introduction
ASP.NET Core SignalR is a library from Microsoft, which in particular provides developers with the ability to include real-time features ...
Read more >
The fall of the BizTalk Architect – From something abstract ...
Both technology and people have become smarter and integration has shifted to a more function based focus. Make it work is more important ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found