C
C#4w ago
Banylog

✅ SignalR Not working

this is a signalr for frontend generated by ai but even this or my own doesnt work, ports are correct connection is made _hubConnection state prints Connected, but when i click button Send with a message nothing happens, other buttons work, Console.WriteLine("EEE"); never prints i need help, the backend is good i have mapped the /chathub and ports are correct i have a frontend web app server and a core web api backend
63 Replies
Luc ♡
Luc ♡4w ago
hm, so to tackle this issue, the first thing i would do is setup logging on the signalr client you can do that via the connection builder like this
connectionBuilder.ConfigureLogging();
connectionBuilder.ConfigureLogging();
Either use your applications dependency injected logger, or just configure a new logger factory e.g.
.ConfigureLogging(logging => {
logging.SetMinimumLevel(LogLevel.Information);
logging.AddConsole();
})
.ConfigureLogging(logging => {
logging.SetMinimumLevel(LogLevel.Information);
logging.AddConsole();
})
Unknown User
Unknown User4w ago
Message Not Public
Sign In & Join Server To View
Banylog
BanylogOP4w ago
okay thank you i have tried from several docs, youtube videos and ai generated from more than 3+, but for some reason, sometimes it doesnt work, now i made again a sepperate blazor web app server without and added what needed, the connection gets created i have added console.write inn each step, the message is send, received but i triggered the send method inside the onInitialize, something goes wrong with the ui, and i cant click buttons neither the deafult ones counter.razor, it like stops working for some reason but the message is received and printed, and the big problem comes when i try connecting with multiple backend server using a load balancer (nginx) with docker, where i put for the .WithUrl in hubcon, the nginx localhost:8080/chathub, but still it cant connect even though everything is correct
Unknown User
Unknown User4w ago
Message Not Public
Sign In & Join Server To View
Luc ♡
Luc ♡4w ago
okay so first of all, i would also suggest what tebeco suggested, make a minimal plain web javascript client to learn about signalr also your issue with the UI not working anymore, that is probably due to a runtime error in the browser, meaning there is probably an exception being thrown in the blazor code, you can check that via the browser consol (technically i can also see this happening when there is an exception being thrown on the server when interactive server is being used, which also is using signalr btw!) then about a load balancer / reverse proxy and having multiple instances of your app running, for the blazor part i would assume you need to enable sticky sessions, atleast when using interactive server, wasm shouldnt matter since its just serving static files i think? For signalr however (assuming we are using websocket), using sticky sessions would also work, however you can get around doing that by skipping the signalr negotiation. This would make it directly connect to the websocket without the prior negotiation request.
Unknown User
Unknown User4w ago
Message Not Public
Sign In & Join Server To View
Banylog
BanylogOP4w ago
if i want to work on top of the blazor, should i change from web app to web assembly?
Unknown User
Unknown User4w ago
Message Not Public
Sign In & Join Server To View
Banylog
BanylogOP4w ago
@page "/" @using Microsoft.AspNetCore.SignalR.Client @inject NavigationManager NavManager
<div class="form-group"> <label> User: <input @bind="userInput"></input> </label> <label> Message: <input @bind="messageInput"></input> </label> </div> <button @onclick="Send">Send</button> <hr /> <ul> @foreach (var message in messages) { <li>@message</li> } </ul> @code { private HubConnection? hubConnection; private List<string> messages = new(); private string? userInput; private string? messageInput; protected override async Task OnInitializedAsync() { Console.WriteLine("Start"); hubConnection = new HubConnectionBuilder() .WithUrl(NavManager.ToAbsoluteUri("/chathub")) .WithAutomaticReconnect() .Build(); Console.WriteLine("Builded"); hubConnection.On<string, string>("ReceiveMessage", (user, message) => { Console.WriteLine("RECEIVED"); var formattedMessage = $"{user}: {message}"; Console.WriteLine(formattedMessage); InvokeAsync(() => { messages.Add(formattedMessage); StateHasChanged(); }); }); await hubConnection.StartAsync(); Console.WriteLine("Started the con"); Console.WriteLine(hubConnection.State); await Send(); } private async Task Send() { Console.WriteLine("Send"); Console.WriteLine(hubConnection?.State); if (hubConnection is not null) { await hubConnection.SendAsync("SendMessage", "Maria", "Hello"); } } public bool IsConnected => hubConnection?.State == HubConnectionState.Connected; } in this base example in blazor, i have added a trigger on initialize cause buttons dont work neither the default counter one, the connection is made, the message is send and received and printed but ui not responsive
Unknown User
Unknown User4w ago
Message Not Public
Sign In & Join Server To View
MODiX
MODiX4w ago
To post C# code type the following: ```cs // code here ``` Get an example by typing $codegif in chat For longer snippets, use: https://paste.mod.gg/
Banylog
BanylogOP4w ago
$code
MODiX
MODiX4w ago
To post C# code type the following: ```cs // code here ``` Get an example by typing $codegif in chat For longer snippets, use: https://paste.mod.gg/
Banylog
BanylogOP4w ago
$codegif
Unknown User
Unknown User4w ago
Message Not Public
Sign In & Join Server To View
Banylog
BanylogOP4w ago
@page "/"
@using Microsoft.AspNetCore.SignalR.Client
@inject NavigationManager NavManager

<div class="form-group">
<label>
User: <input @bind="userInput"></input>
</label>
<label>
Message: <input @bind="messageInput"></input>
</label>
</div>
<button @onclick="Send">Send</button>

<hr />

<ul>
@foreach (var message in messages)
{
<li>@message</li>
}
</ul>


@code {
private HubConnection? hubConnection;
private List<string> messages = new();
private string? userInput;
private string? messageInput;

protected override async Task OnInitializedAsync()
{

Console.WriteLine("Start");

hubConnection = new HubConnectionBuilder()
.WithUrl(NavManager.ToAbsoluteUri("/chathub"))
.WithAutomaticReconnect()
.Build();

Console.WriteLine("Builded");

hubConnection.On<string, string>("ReceiveMessage", (user, message) =>
{
Console.WriteLine("RECEIVED");

var formattedMessage = $"{user}: {message}";
Console.WriteLine(formattedMessage);
InvokeAsync(() =>
{
messages.Add(formattedMessage);
StateHasChanged();
});
});

await hubConnection.StartAsync();

Console.WriteLine("Started the con");
Console.WriteLine(hubConnection.State);


await Send();
}

private async Task Send()
{
Console.WriteLine("Send");
Console.WriteLine(hubConnection?.State);

if (hubConnection is not null)
{
await hubConnection.SendAsync("SendMessage", "Maria", "Hello");
}
}

public bool IsConnected => hubConnection?.State == HubConnectionState.Connected;

}
@page "/"
@using Microsoft.AspNetCore.SignalR.Client
@inject NavigationManager NavManager

<div class="form-group">
<label>
User: <input @bind="userInput"></input>
</label>
<label>
Message: <input @bind="messageInput"></input>
</label>
</div>
<button @onclick="Send">Send</button>

<hr />

<ul>
@foreach (var message in messages)
{
<li>@message</li>
}
</ul>


@code {
private HubConnection? hubConnection;
private List<string> messages = new();
private string? userInput;
private string? messageInput;

protected override async Task OnInitializedAsync()
{

Console.WriteLine("Start");

hubConnection = new HubConnectionBuilder()
.WithUrl(NavManager.ToAbsoluteUri("/chathub"))
.WithAutomaticReconnect()
.Build();

Console.WriteLine("Builded");

hubConnection.On<string, string>("ReceiveMessage", (user, message) =>
{
Console.WriteLine("RECEIVED");

var formattedMessage = $"{user}: {message}";
Console.WriteLine(formattedMessage);
InvokeAsync(() =>
{
messages.Add(formattedMessage);
StateHasChanged();
});
});

await hubConnection.StartAsync();

Console.WriteLine("Started the con");
Console.WriteLine(hubConnection.State);


await Send();
}

private async Task Send()
{
Console.WriteLine("Send");
Console.WriteLine(hubConnection?.State);

if (hubConnection is not null)
{
await hubConnection.SendAsync("SendMessage", "Maria", "Hello");
}
}

public bool IsConnected => hubConnection?.State == HubConnectionState.Connected;

}
in this base example in blazor, i have added a trigger on initialize cause buttons dont work neither the default counter one, the connection is made, the message is send and received and printed but ui not responsive finaly
Unknown User
Unknown User4w ago
Message Not Public
Sign In & Join Server To View
Banylog
BanylogOP4w ago
its the bare minimum example i was talking at start [2025-10-29T16:40:16.787Z] Error: Connection disconnected with error 'Error: Server returned an error on close: Connection closed with an error.'. log @ blazor.web.js:1 _stopConnection @ blazor.web.js:1 (anonymous) @ blazor.web.js:1 _close @ blazor.web.js:1 stop @ blazor.web.js:1 _stopInternal @ blazor.web.js:1 await in _stopInternal
stop @ blazor.web.js:1 _processIncomingData @ blazor.web.js:1 (anonymous) @ blazor.web.js:1 (anonymous) @ blazor.web.js:1 blazor.web.js:1 Uncaught (in promise) Error: Server returned an error on close: Connection closed with an error. at gn._processIncomingData (blazor.web.js:1:60595) at xn.onreceive (blazor.web.js:1:53760) at WebSocket.<anonymous> (blazor.web.js:1:81866) _processIncomingData @ blazor.web.js:1 (anonymous) @ blazor.web.js:1 (anonymous) @ blazor.web.js:1 these popped up in the console
Unknown User
Unknown User4w ago
Message Not Public
Sign In & Join Server To View
Luc ♡
Luc ♡4w ago
yes, did see that before, never looked into sub protocols like that before though :D
Unknown User
Unknown User4w ago
Message Not Public
Sign In & Join Server To View
Luc ♡
Luc ♡4w ago
I think this is the most important point here. Why do you want to use blazor and make a signalr connection? In web assembly it would make sense, if your not doing blazor wasm, than this doesnt make much sense unless your using a different service's signalr hub, which from the looks of it, you arent doing?)
Unknown User
Unknown User4w ago
Message Not Public
Sign In & Join Server To View
Luc ♡
Luc ♡4w ago
yeee
Unknown User
Unknown User4w ago
Message Not Public
Sign In & Join Server To View
Banylog
BanylogOP4w ago
i was told to start with blazor web app server for frontend, the goal:
MODiX
MODiX4w ago
Please don't upload any potentially harmful files @Banylog, your message has been removed
Banylog
BanylogOP4w ago
i cant upload a picture pdf
Luc ♡
Luc ♡4w ago
you sent a pdf yes
Banylog
BanylogOP4w ago
1 sec
Unknown User
Unknown User4w ago
Message Not Public
Sign In & Join Server To View
Banylog
BanylogOP4w ago
i send picture 1 sec goal is to make a full stack chat app using .net c# with load balancer 2 databases mysql, mongodb
Unknown User
Unknown User4w ago
Message Not Public
Sign In & Join Server To View
Banylog
BanylogOP4w ago
i have done all except this signalr cause this errors
Luc ♡
Luc ♡4w ago
interesting choice first of all your atleast gonna need one more "database" for a backplane for signalr if you want to have your backend be "multi" instances (assuming thats what you mean when talking about using lb's)
Unknown User
Unknown User4w ago
Message Not Public
Sign In & Join Server To View
Banylog
BanylogOP4w ago
oh yeah i forgot
Luc ♡
Luc ♡4w ago
ye, redis is my to go to aswell for that
Banylog
BanylogOP4w ago
i have redis for caching/ for the signalr but signalr problems
Unknown User
Unknown User4w ago
Message Not Public
Sign In & Join Server To View
Banylog
BanylogOP4w ago
yeah i know
Unknown User
Unknown User4w ago
Message Not Public
Sign In & Join Server To View
Luc ♡
Luc ♡4w ago
signalr uses redis for its pub/sub
Unknown User
Unknown User4w ago
Message Not Public
Sign In & Join Server To View
Banylog
BanylogOP4w ago
chat application
Unknown User
Unknown User4w ago
Message Not Public
Sign In & Join Server To View
Banylog
BanylogOP4w ago
what you mean
Unknown User
Unknown User4w ago
Message Not Public
Sign In & Join Server To View
Luc ♡
Luc ♡4w ago
i think so too yes, you need to understand both signalr and blazor independently first. im assuming tebeco is gonna explain the interactivity models now
Unknown User
Unknown User4w ago
Message Not Public
Sign In & Join Server To View
Banylog
BanylogOP4w ago
oh show i should use blazor web assembly cause its client side? so*
Unknown User
Unknown User4w ago
Message Not Public
Sign In & Join Server To View
Banylog
BanylogOP4w ago
okay thanks for the help, i appreciate it
Unknown User
Unknown User4w ago
Message Not Public
Sign In & Join Server To View
Luc ♡
Luc ♡4w ago
BleepingComputer
Microsoft: DNS outage impacts Azure and Microsoft 365 services
Microsoft is suffering an ongoing DNS outage affecting customers worldwide, preventing them from logging into company networks and accessing Microsoft Azure and Microsoft 365 services.
Unknown User
Unknown User4w ago
Message Not Public
Sign In & Join Server To View
Banylog
BanylogOP4w ago
thanks a lot
Unknown User
Unknown User4w ago
Message Not Public
Sign In & Join Server To View
MODiX
MODiX4w ago
If you have no further questions, please use /close to mark the forum thread as answered
Unknown User
Unknown User4w ago
Message Not Public
Sign In & Join Server To View
Banylog
BanylogOP4w ago
$close
MODiX
MODiX4w ago
If you have no further questions, please use /close to mark the forum thread as answered

Did you find this page helpful?