-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
Hi!
I'm mantaining this library https://www.nuget.org/packages/ABnet.WarehouseSimulator.Client which depends on Microsoft.AspNetCore.SignalR.Client > 7.0.11 .
I'm facing some problems when using this library on Blazor Apps running .NET 8 because it is forcing to use JSON Protocol 2, even though the library does not have any reference to the StatefulReconnect. I think this may be a bug related to it.
This is the source code of the library related to this bug:
hubConnection = new HubConnectionBuilder()
.ConfigureLogging(hubLoggingOptions ?? ((loggingBuilder) =>
{
loggingBuilder.SetMinimumLevel(LogLevel.Information);
loggingBuilder.AddConsole();
}))
.WithUrl($"{options.ServerAddress}/hubs/adapter", options =>
{
options.Headers.Add("X-API-Key", this.options.ApiKey);
options.CloseTimeout = TimeSpan.FromSeconds(10);
})
.WithAutomaticReconnect()
.Build();
And these are the logs when running one Blazor App project which uses this library under .NET 8.0:
info: Microsoft.AspNetCore.Http.Connections.Client.HttpConnection[3]
HttpConnection Started.
info: Microsoft.AspNetCore.SignalR.Client.HubConnection[24]
Using HubProtocol 'json v2'.
fail: Microsoft.AspNetCore.SignalR.Client.HubConnection[36]
Server returned handshake error: The server does not support version 2 of the 'json' protocol.
info: Microsoft.AspNetCore.Http.Connections.Client.Internal.WebSocketsTransport[11]
WebSocket closed by the server. Close status NormalClosure.
fail: Microsoft.AspNetCore.SignalR.Client.HubConnection[43]
Error starting connection.
Microsoft.AspNetCore.SignalR.HubException: Unable to complete handshake with the server due to an error: The server does not support version 2 of the 'json' protocol.
at Microsoft.AspNetCore.SignalR.Client.HubConnection.HandshakeAsync(ConnectionState startingConnectionState, CancellationToken cancellationToken)
at Microsoft.AspNetCore.SignalR.Client.HubConnection.StartAsyncCore(CancellationToken cancellationToken)
info: Microsoft.AspNetCore.Http.Connections.Client.Internal.WebSocketsTransport[6]
Transport is stopping.
info: Microsoft.AspNetCore.Http.Connections.Client.HttpConnection[6]
HttpConnection Disposed.
When running the BlazorApp under .NET 7.0 it uses Json Protocol 1 and the error doesn't occurs:
info: Microsoft.AspNetCore.Http.Connections.Client.Internal.WebSocketsTransport[1]
Starting transport. Transfer mode: Text. Url: 'wss://simulator-runner-01.abnet.dev/hubs/adapter?id=h1GZgyS5EkE4ZfIj8co22A'.
info: Microsoft.AspNetCore.Http.Connections.Client.HttpConnection[3]
HttpConnection Started.
info: Microsoft.AspNetCore.SignalR.Client.HubConnection[24]
Using HubProtocol 'json v1'.
info: Microsoft.AspNetCore.SignalR.Client.HubConnection[44]
HubConnection started.
I think my issue is directly related to the PR #50442 , right?
Wasn't it solved already or am I missing something?
Expected Behavior
I was expecting SignalR HubConnectionBuilder to keep using JsonProtocol version 1 if I'm not using StatefulReconnect and the server that it is trying to connect to doesn't supports Json Version 2.
Steps To Reproduce
Created this repo. More details on ReadMe:
https://github.com/guilhermecampello/SignalRJsonProtocolTest/tree/master
Exceptions (if any)
fail: Microsoft.AspNetCore.SignalR.Client.HubConnection[36]
Server returned handshake error: The server does not support version 2 of the 'json' protocol.
.NET Version
8.0.100
Anything else?
Apparently this bug only happens on Blazor Apps. On console applications I wasn't able to reproduce.