I'm trying to run an Azure function using SignalR output binding in dotnet-isolated process, but I always have this error

"Executed 'Functions.SendToGroup' (Failed,..) System.Private.CoreLib: Exception while executing function: Functions.SendToGroup. Microsoft.Azure.SignalR.Management: ServiceEndpoints is empty. ConnectionString is null, empty, or consists only of white-space."

either running it locally or remotely.

The connection string is defined in the local.settings,json file using the key

"AzureSignalRConnectionString": "" 

This is the code of the input and output Azure functions (taken from the example here https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-signalr-service-output?tabs=isolated-process&pivots=programming-language-csharp)

        [Function("negotiate")]
        public static string Negotiate(
            [HttpTrigger(AuthorizationLevel.Anonymous)] HttpRequestData req,
            [SignalRConnectionInfoInput(HubName = "dttelemetry")] string connectionInfo)
        {
            // The serialization of the connection info object is done by the framework. It should be camel case. The SignalR client respects the camel case response only.
            return connectionInfo;
        }
    [Function("SendToGroup")]
    [SignalROutput(HubName = "dttelemetry", ConnectionStringSetting = "SignalRConnection")]
    public static SignalRMessageAction SendToGroup([HttpTrigger(AuthorizationLevel.Anonymous, "post")] HttpRequestData req)
    {
        using var bodyReader = new StreamReader(req.Body);
        SignalRMessageAction messageAction =  new SignalRMessageAction("newMessage")
        {
            Arguments = new[] { bodyReader.ReadToEnd() },
            GroupName = "groupToSend"
        };
        return messageAction;
    }

local.settings.json

{
"IsEncrypted": false,
"Values": {
"FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated",
"AzureWebJobsStorage": "\<My AzureWebJobsStorage\> ",
"AzureSignalRConnectionString": "\<My SignalR Connection string\>"
}
}

Function App Configuration

I checked this previous StackOverflow question Deployed Azure SignalR Function Failed: The SignalR Service connection string or endpoints are not set, but it didn't answer my problem

1

There are 1 best solutions below

0
On

Here is the fix for this problem https://learn.microsoft.com/en-us/answers/questions/1331784/azure-functions-signalr-output-binding-failure-ser

While AzureSignalRConnectionString is the default name for the app setting that contains the connection string for the SignalR binding, since you are setting the ConnectionStringSetting argument in the attribute, you need to use that value instead.

So, the name/key of the app setting, both when running on Azure or via local.settings.json, use SignalRConnection instead of AzureSignalRConnectionString.

I changed the definition of SignalROutput:
[Function("SendToGroup")] [SignalROutput(HubName = "dttelemetry", ConnectionStringSetting = "AzureSignalRConnectionString")]