Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blazor Client-Side: Unable to create a SignalR connection in a C# Service #13503

Closed
CalaxDev opened this issue Aug 28, 2019 · 19 comments
Closed
Labels
area-blazor Includes: Blazor, Razor Components area-signalr Includes: SignalR clients and servers Blazor ♥ SignalR This issue is related to the experience of Signal R and Blazor working together Components Big Rock This issue tracks a big effort which can span multiple issues enhancement This issue represents an ask for new feature or an enhancement to an existing one feature-blazor-wasm This issue is related to and / or impacts Blazor WebAssembly
Projects

Comments

@CalaxDev
Copy link

Describe the bug

I have set up a hosted Blazor Client-Side Application and have added a SignalR-Connection to my Server (Calling endpoints.MapHub("/somePath").

Now I tried to connect to this SignalR-Hub in a C#-Service in ClientSide-Blazor - However, this does not work as expected - I am receiving some strange Exception upon trying to call StartAsync on the HubConnection:

Could not resolve type with token 0100003f from typeref (expected class 'Microsoft.Extensions.Logging.Abstractions.Internal.NullScope' in assembly 'Microsoft.Extensions.Logging.Abstractions, Version=2.2.0.0, Culture=neutral, PublicKeyToken=abd9793829ddae60')

However, when trying to connect to the same hub through JavaScript, it works (as expected) flawlessly, so it's not a problem of my Hub or Server...

Expected behavior

The Connection should be able to be established without error

Screenshots

I attached some Screenshots with more Information.
2019-08-28_10h25_07
2019-08-28_10h25_43
2019-08-28_10h26_11

The "StartIfNeededAsync"-Method is called on a Razor Page after a Buttonclick:

@inject SignalRService signalr
.....
<button @onclick="start">Test start</button>
...
protected async Task start()
    {
        await signalr.StartIfNeededAsync();
    }

Additional context

Add any other context about the problem here.
Include the output of dotnet --info

.NET Core SDK (gemäß "global.json"):
Version: 3.0.100-preview8-013656
Commit: 8bf06ffc8d

Laufzeitumgebung:
OS Name: Windows
OS Version: 10.0.17134
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\3.0.100-preview8-013656\

Host (useful for support):
Version: 3.0.0-preview8-28405-07
Commit: d01b2fb7bc

.NET Core SDKs installed:
2.0.2 [C:\Program Files\dotnet\sdk]
2.0.3 [C:\Program Files\dotnet\sdk]
2.1.202 [C:\Program Files\dotnet\sdk]
2.1.502 [C:\Program Files\dotnet\sdk]
2.1.503 [C:\Program Files\dotnet\sdk]
2.1.505 [C:\Program Files\dotnet\sdk]
2.1.507 [C:\Program Files\dotnet\sdk]
2.1.600-preview-009472 [C:\Program Files\dotnet\sdk]
2.1.700-preview-009597 [C:\Program Files\dotnet\sdk]
2.1.800-preview-009677 [C:\Program Files\dotnet\sdk]
2.1.800-preview-009696 [C:\Program Files\dotnet\sdk]
3.0.100-preview8-013656 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
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.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
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.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.0.0-preview7.19365.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.0.0-preview8.19405.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.0.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.0.9 [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.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.0.0-preview7-27912-14 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.0.0-preview8-28405-07 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.0.0-preview7-27912-14 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 3.0.0-preview8-28405-07 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

@mkArtakMSFT mkArtakMSFT added area-blazor Includes: Blazor, Razor Components feature-blazor-wasm This issue is related to and / or impacts Blazor WebAssembly labels Aug 28, 2019
@mkArtakMSFT mkArtakMSFT added this to the blazor-wasm milestone Aug 28, 2019
@mkArtakMSFT
Copy link
Member

Thanks for contacting us, @Z3roCoder.
The .Net Core SignalR client is not compatible with Blazor Client at the moment.
You can instead use JS Interop with SignalR javascript client and that should work.
Also, have a look at these community projects, which have done this already:

@CalaxDev
Copy link
Author

Thanks for your reply,

I'm wondering - How expensive is the C#/JS Interop actually?

And is it planned that Client Side Blazor will support the SignalR Client in the future?

My goal actually was to achieve a constant data streaming from the server to the Client - As a sort of Log-Streaming, and I thought SignalR would be the way to go here.

@mkArtakMSFT
Copy link
Member

We'll be using this issue to track the work necessary to support SignalR client on Blazor Client-side. So yes, we expect that this will work at some point.

@CalaxDev
Copy link
Author

Alright - Thank you for your fast response! I'll be looking forward to see this work!

@ChristianWeyer
Copy link

Hi @mkArtakMSFT - do you have any detailed explanation of why the SignalR .NET Core client is not compatible to be used with Client-side Blazor?
Thanks!

@mkArtakMSFT
Copy link
Member

mkArtakMSFT commented Oct 25, 2019

I don't remember the exact reason, @ChristianWeyer, but this may be because of the lack of WebSocket support onthe underlying Mono platform. @SteveSandersonMS do I remember this right?

@SteveSandersonMS
Copy link
Member

@ChristianWeyer It's because .NET's built-in websockets APIs are built on underlying TCP networking APIs that can't ever work in the browser, since JavaScript doesn't expose raw TCP networking capabilities. This naturally leads to a runtime failure from somewhere low in the stack. What we have to do to make it work is provide a browser-compatible implementation of the relevant low-level websocket APIs that are implemented by calling the JavaScript websocket APIs.

As it happens, this work has already been done. We just haven't integrated it yet. Once it is integrated, my expectation is that the SignalR client should just start working.

@ChristianWeyer
Copy link

Thanks for the update @SteveSandersonMS - great!

@mkArtakMSFT mkArtakMSFT added the enhancement This issue represents an ask for new feature or an enhancement to an existing one label Nov 6, 2019
@mkArtakMSFT
Copy link
Member

@anurse is there a separate issue tracking this? Or should this one be used to track this work?

@mkArtakMSFT mkArtakMSFT added the Blazor ♥ SignalR This issue is related to the experience of Signal R and Blazor working together label Nov 11, 2019
@analogrelay
Copy link
Contributor

I'm fine to use this issue. We should make sure it's in area-signalr so we see it in triage though ;). Happy to have it in both areas though.

@analogrelay analogrelay added the area-signalr Includes: SignalR clients and servers label Nov 12, 2019
@mkArtakMSFT mkArtakMSFT added the Components Big Rock This issue tracks a big effort which can span multiple issues label Nov 13, 2019
@RedWingBB
Copy link

Is this work expected to release in core 3.2?

Consider cases where a webapi is already written using the full framework.
Is it expected that a .net core client will be able to connect to an asp.net/full framework hub?

@SteveSandersonMS
Copy link
Member

Yes, it will work in the 3.2 release. We have a plan for making it work.

@BrennanConroy
Copy link
Member

Is it expected that a .net core client will be able to connect to an asp.net/full framework hub?

No, ASP.NET SignalR is not compatible with ASP.NET Core SignalR.

@analogrelay
Copy link
Contributor

@SteveSandersonMS @BrennanConroy anything remaining here? SignalR should be working for Blazor WASM apps (with some other bugs that are otherwise tracked).

@BrennanConroy
Copy link
Member

I think this can be closed

@analogrelay
Copy link
Contributor

I'll close it then! If anyone is seeing this kind of issue using SignalR Client on Blazor WASM, feel free to open a new issue!

Blazor WASM automation moved this from 3.2 - Preview 3 to Done Feb 12, 2020
@CalaxDev
Copy link
Author

Awesome to see this resolved now!
Only wanting to ask - What package would I need to have Blazor WASM communicate via SignalR now, without using a JavaScript library like I ended up doing?
Could someone write up a few little Steps of how to go about it with the changes now? Thank you!

@brikken
Copy link

brikken commented Feb 13, 2020

@Z3roCoder I assume you should simply use the .NET client, as described in the SignalR docs

@ghost ghost locked as resolved and limited conversation to collaborators Mar 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components area-signalr Includes: SignalR clients and servers Blazor ♥ SignalR This issue is related to the experience of Signal R and Blazor working together Components Big Rock This issue tracks a big effort which can span multiple issues enhancement This issue represents an ask for new feature or an enhancement to an existing one feature-blazor-wasm This issue is related to and / or impacts Blazor WebAssembly
Projects
No open projects
Blazor WASM
  
Done
Development

No branches or pull requests

9 participants