Aspnetcore: Extra SignalR hubs in a Server-side Blazor app throw exceptions

Created on 22 Apr 2019  路  5Comments  路  Source: dotnet/aspnetcore

Describe the bug

In aspnetcore-preview-4, I can no longer use other SignalR Hubs at the same time as running Server-Side Blazor. My prev-3 project was running fine. When I completed the upgrade to prev-4, I could not get any clients to connect to the hub I have setup in UseEndpoints. The error message is always:

Error: Server returned handshake error: The protocol 'json' is not supported.

If I try to replace the AddNewtonsoftJsonProtocol with AddMessagePackProtocol, and setup my client to use MessagePack, the client says the messagepack protocol is not supported.

To Reproduce

Steps to reproduce the behavior:

  1. Using preview 4 of ASP.NET Core
  2. Create a default Server-side Blazor app (Razor Components template still)
  3. Add all the standard SignalR setup including AddNewtonsoftJsonProtocol
  4. Setup a client to connect to the hub and watch the error.

I've also got my source code here:
https://github.com/limefrogyank/DynamicData/tree/master/DynamicData.SignalR.JSInterop.TestBlazorApp
A javascript client attempted to connect (in wwwroot/dynamicDataSignalRInterop.js) when the Index.razor page is displayed. The call to the javascript file is deep, deep in the SignalRSourceCache class... but it was working fine in prev 3.

Expected behavior

The hub should connect (complete handshaking) and start passing data.

Screenshots

If applicable, add screenshots to help explain your problem.

Additional context

Output of dotnet --info

.NET Core SDK (reflecting any global.json):
 Version:   3.0.100-preview4-011223
 Commit:    118dd862c8

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.18362
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\3.0.100-preview4-011223\

Host (useful for support):
  Version: 3.0.0-preview4-27615-11
  Commit:  ee54d4cbd2

.NET Core SDKs installed:
  2.1.202 [C:\Program Files\dotnet\sdk]
  2.1.402 [C:\Program Files\dotnet\sdk]
  2.1.403 [C:\Program Files\dotnet\sdk]
  2.1.500 [C:\Program Files\dotnet\sdk]
  2.1.502 [C:\Program Files\dotnet\sdk]
  2.1.504 [C:\Program Files\dotnet\sdk]
  2.1.600-preview-009426 [C:\Program Files\dotnet\sdk]
  2.1.600-preview-009472 [C:\Program Files\dotnet\sdk]
  2.1.600-preview-009497 [C:\Program Files\dotnet\sdk]
  2.1.600 [C:\Program Files\dotnet\sdk]
  2.1.601 [C:\Program Files\dotnet\sdk]
  2.1.602 [C:\Program Files\dotnet\sdk]
  2.1.700-preview-009597 [C:\Program Files\dotnet\sdk]
  2.2.101 [C:\Program Files\dotnet\sdk]
  3.0.100-preview4-011223 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.2.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.2.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.0.0-preview4-19216-03 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.2.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.0.0-preview4-27615-11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.0.0-preview4-27613-28 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
accepted area-signalr bug

All 5 comments

@anurse Thoughts on this?

We're taking a look into this rn

We've figured out the issue and have a fix. There was an issue with how we were copying protocols across Hub and Hub<T>

For now you can workaround the issue by providing your own hub options for your custom hub and adding the protocols you want to support:

services.AddServerSideBlazor()
    .AddSignalR()
    .AddHubOptions<DynamicData.SignalR.DynamicDataCacheHub<TestModel.Person, string, TestContext>>(options =>
{
    options.SupportedProtocols = new List<string>(); // This is important otherwise you might accidentally break blazor
    options.SupportedProtocols.Add("json");
    // options.SupportedProtocols.Add("messagepack"); // Uncomment if you added MessagePack
});

Thanks! Can confirm this works. It was giving me errors when I tried to change the options for all hubs under UseSignalR(options=>...)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pekkah picture pekkah  路  200Comments

zorthgo picture zorthgo  路  136Comments

rmarinho picture rmarinho  路  78Comments

danroth27 picture danroth27  路  79Comments

reduckted picture reduckted  路  91Comments