Skip to content

SignalR failing to send messages to client #43950

@NicolaiJee

Description

@NicolaiJee

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

I have a web api .net 6.
I am trying to send messages to a client application.
My registration of SignalR looks this:

            services.AddSignalR(o => o.EnableDetailedErrors = true)
            .AddAzureSignalR(m => { m.ConnectionString = Configuration["AzureSignalRConnectionString"];});
    app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();

                endpoints.MapHub<ImportAssignmentHub>("/importassignmenthub");

            });

I use injection like this
IHubContext<ImportAssignmentHub> importAssignmentHub

And send messages like this

await _importAssignmentHub.Clients.Group(userName).SendAsync("SendNumberOfRows", maxRowNumber);

I have also tried to inject ImportAssignmentHub as a singleton use it directly
These events are triggered:


    public override Task OnConnectedAsync()
        {
            string name = Context.User.Identity.Name;

            name = !string.IsNullOrWhiteSpace(name) ? name : Context.User.Claims.FirstOrDefault(m => m.Type.Equals("name", StringComparison.InvariantCultureIgnoreCase))?.Value;

            if (!string.IsNullOrWhiteSpace(name))
            {
                TrackException(name + " has been connected");
            }
            return base.OnConnectedAsync();
        }
        public override Task OnDisconnectedAsync(Exception exception)
        {
            string name = Context.User.Identity.Name;

            name = !string.IsNullOrWhiteSpace(name) ? name : Context.User.Claims.FirstOrDefault(m => m.Type.Equals("name", StringComparison.InvariantCultureIgnoreCase))?.Value;
             if (!string.IsNullOrWhiteSpace(name))
            {
                TrackException(name + " has been disconnected");
            }
            return base.OnDisconnectedAsync(exception);
        }

And I can see that my username is correct.

From the live trace log in can only see this when connecting:
image

Any help would be greatly appriciated, as I have been trying everything for 2 days now.

Expected Behavior

No response

Steps To Reproduce

No response

Exceptions (if any)

No response

.NET Version

.net 6

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs: Attention 👋This issue needs the attention of a contributor, typically because the OP has provided an update.area-signalrIncludes: SignalR clients and servers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions