Adding/removing users to signalR groups in .NET 5.0

Viewed 275

The following code has been working in .netcoreapp3.1 but it stopped working after migrating the Http-triggered function to .NET 5.0:

public static class AddToGroup
    {
        [Function("addtogroup")]
        public static Task Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", Route = "addtogroup/{trnantId}/{userId}")]
            HttpRequestData req,
            string tenantId,
            string userId,
            [SignalR(HubName = "testhub")]
            IAsyncCollector<SignalRGroupAction> signalRGroupActions,
            FunctionContext executionContext)
        {
            return signalRGroupActions.AddAsync(new SignalRGroupAction
            {
                UserId = $"{tenantId}_{userId}",
                GroupName = tenantId,
                Action = GroupAction.Add
            });
        }
    }

Could anybody throw a guidance on an equivalent of this code in .NET 5.0?

1 Answers

As the error from compiler says: "...Attribute 'SignalROutput' is not valid on this declaration type. It is only valid on 'method, property, indexer' declarations....". You should put the [SignalR(HubName = "testhub")] attribute on the method. Here is a sample.

You can also see in the .Net 5 sample that the return type MyMessage has the same structure with the previous SignalRMessage in sample for .NET class library function apps.

Related