failed to make Windows Desktop UI App in .Net Framework 4.8 SignalR client to connect to .Net Core SignalR Server

Net Wang 40 Reputation points
2025-01-11T16:42:11.73+00:00

I can make IIS ASP.NET .Net Framework 4.8 SignalR client to connect to .Net Core SignalR Server.

But I failed to make Windows Desktop UI App in .Net Framework 4.8 SignalR client to connect to .Net Core SignalR Server.

.Net Core SignalR Server:
        IIS ASP.Net Core 8.0,
        Microsoft.AspNetCore.SignalR 1.1.0,
        Microsoft.AspNetCore.SignalR.Core 1.1.0,
        Angular,
        Javascript (Browser) successfully made SignalR connection to .Net Core SignalR Server

SignalR Client 1:
    IIS ASP.NET 4.8,
    Microsoft.AspNetCore.SignalR.Client 8.0.0.0,
    Microsoft.AspNetCore.SignalR.Client.Core 8.0.0.0,
    successfully made SignalR connection to .Net Core SignalR Server

SignalR Client 2:
   Windows C# Desktop UI App in .NET Framework 4.8,
   Microsoft.AspNetCore.SignalR.Client 8.0.0.0,
   Microsoft.AspNetCore.SignalR.Client.Core 8.0.0.0,
   Failed to make SignalR connection to .Net Core SignalR Server

Connection = new HubConnectionBuilder()
    .WithUrl("http://localhost/QMOSRFactor/rfactor",
        options => {
            options.Transports = HttpTransportType.WebSockets;
        })
    .WithAutomaticReconnect()
    .Build();


await Connection.StartAsync();

For SignalR Client 2, after calling await Connection.StartAsync(), nothing happened. No error in Visual Studio Output. No exceptions throwed.

If I wrapped the above code in netstandard2.0 library. Reference this library in Client 2 project. Nothing happened. No error in Visual Studio Output. No exceptions.

Azure SignalR Service
Azure SignalR Service
An Azure service that is used for adding real-time communications to web applications.
157 questions
{count} votes

Accepted answer
  1. Harshitha Veeramalla 421 Reputation points Microsoft External Staff
    2025-02-12T06:55:52.43+00:00

    Hi @Net Wang

    I'm glad that you were able to resolve your issue and thank you for posting your solution so that others experiencing the same thing can easily reference this!

    Since the Microsoft Q&A community has a policy that "The question author cannot accept their own answer. They can only accept answers by others ", I'll repost your solution in case you'd like to "Accept " the answer.

    Issue :

    Windows Desktop UI App (SignalR Client 2) in .NET Framework 4.8** is failing to establish a SignalR connection with your .NET Core 8 SignalR Server, while other clients (ASP.NET 4.8 and JavaScript) are able to connect successfully.

    The problem occurs when calling:

    await Connection.StartAsync();

    Solution :

    solved the issue by embedding in a new Task which is different from Windows Form UI thread

    Run StartAsync() on a separate Task to avoid blocking the UI thread:

    
    Task.Factory.StartNew(() => 
    
    {
    
        await Connection.StartAsync();
    
    });
    
    

    Please click Accept Answer and kindly upvote it so that other people who faces similar issue may get benefitted from it.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Net Wang 40 Reputation points
    2025-01-29T13:32:35.3966667+00:00

    solved the issue by embedding in a new Task which is different from Windows Form UI thread

    Task.Factory.StartNew(() => {

         await Connection.StartAsync();
    

    });


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.