3

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?

Arash
  • 3,628
  • 5
  • 46
  • 70
  • 1
    Sure would be nice if 2 months later there was anything. This comment is made in solidarity of dealing with this genuinely fun time of trying to migrate to 5.0 while also using Azure. – Captain Prinny May 24 '21 at 13:40

1 Answers1

1

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.

sindo
  • 19
  • 3
  • Putting the compile error aside, how users can be added to a signalR messaging group or how to remove a user from the group? – Arash Mar 29 '21 at 13:31
  • Previously you add a `SignalRGroupAction` to the `IAsyncCollector`, now you can just return the `SignalRGroupAction` from the method. – sindo Mar 30 '21 at 06:29
  • where is this point documented on Microsoft's documents website? @sindo – Arash Mar 31 '21 at 00:05
  • Docs: https://learn.microsoft.com/en-us/azure/azure-functions/dotnet-isolated-process-guide#output-bindings – sindo Mar 31 '21 at 04:02
  • You can also take a look at [Differences with .NET class library functions](https://learn.microsoft.com/en-us/azure/azure-functions/dotnet-isolated-process-guide#differences-with-net-class-library-functions). – sindo Mar 31 '21 at 04:50
  • 1
    none of those documents that you shared are talking about this topic neither clearly nor explicitly. Would you please show me the exact spot in those documents so that one can conclude your answer? – Arash Mar 31 '21 at 11:30
  • There seems to be a huge rash of people linking that exact page and indicating that it demonstrates how to migrate existing code, when it, in fact, does nothing of the sort. – Captain Prinny May 24 '21 at 13:41