Azure functions c# 5 SignalR Setup

John Harris 21 Reputation points
2021-04-28T16:02:26.477+00:00

I'm attempting to use SignalR in an Azure functions app with .net 5. I have the Nugets:
Microsoft.Azure.Functions.Worker.Extensions.SignalRService
Microsoft.Azure.WebJobs.Extensions.SignalRService

My Hub is very simple:
public class SiteHub : ServerlessHub
{
[Function("negotiate")]
public async Task<SignalRConnectionInfo> Negotiate([HttpTrigger(AuthorizationLevel.Anonymous)] HttpRequest req)
{
return await NegotiateAsync(new Microsoft.Azure.SignalR.Management.NegotiationOptions { IsDiagnosticClient = true });
}
}

I'm not sure how properly set up the connection string. The isolated version of dotnet seems to handle this a little differently than the normal version.

This is the stack trace I'm getting
[2021-04-28T15:44:19.274Z] Executed 'Functions.negotiate' (Failed, Id=601c4466-5aea-4474-ba79-5db74d8376e0, Duration=191ms) [2021-04-28T15:44:19.276Z] System.Private.CoreLib: Exception while executing function: Functions.negotiate. System.Private.CoreLib: Result: Failure Exception: System.NullReferenceException: Object reference not set to an instance of an object. [2021-04-28T15:44:19.278Z] at Microsoft.Azure.WebJobs.Extensions.SignalRService.StaticServiceHubContextStore.Get(String connectionStringSetting) [2021-04-28T15:44:19.279Z] at Microsoft.Azure.WebJobs.Extensions.SignalRService.ServerlessHub..ctor(IServiceHubContext hubContext, IServiceManager serviceManager) [2021-04-28T15:44:19.280Z] at IOX.PlantDocs.Functions.SiteHub..ctor() [2021-04-28T15:44:19.281Z] --- End of stack trace from previous location --- [2021-04-28T15:44:19.282Z] at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.ConstructorMatcher.CreateInstance(IServiceProvider provider) [2021-04-28T15:44:19.284Z] at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.CreateInstance(IServiceProvider provider, Type instanceType, Object[] parameters) [2021-04-28T15:44:19.287Z] at Microsoft.Azure.Functions.Worker.DefaultFunctionActivator.CreateInstance(Type instanceType, FunctionContext context) in D:\a\1\s\src\DotNetWorker.Core\Invocation\DefaultFunctionActivator.cs:line 23 [2021-04-28T15:44:19.289Z] at Microsoft.Azure.Functions.Worker.Invocation.DefaultFunctionInvoker2.CreateInstance(FunctionContext context) in D:\a\1\s\src\DotNetWorker.Core\Invocation\DefaultFunctionInvoker.cs:line 26 [2021-04-28T15:44:19.291Z] at Microsoft.Azure.Functions.Worker.Invocation.DefaultFunctionExecutor.ExecuteAsync(FunctionContext context) in D:\a\1\s\src\DotNetWorker.Core\Invocation\DefaultFunctionExecutor.cs:line 27 [2021-04-28T15:44:19.292Z] at Microsoft.Azure.Functions.Worker.OutputBindings.OutputBindingsMiddleware.Invoke(FunctionContext context, FunctionExecutionDelegate next) in D:\a\1\s\src\DotNetWorker.Core\OutputBindings\OutputBindingsMiddleware.cs:line 13 [2021-04-28T15:44:19.294Z] at Microsoft.Azure.Functions.Worker.GrpcWorker.InvocationRequestHandlerAsync(InvocationRequest request, IFunctionsApplication application, IInvocationFeaturesFactory invocationFeaturesFactory, ObjectSerializer serializer, IOutputBindingsInfoProvider outputBindingsInfoProvider) in D:\a\1\s\src\DotNetWorker.Grpc\GrpcWorker.cs:line 166 Stack: at Microsoft.Azure.WebJobs.Extensions.SignalRService.StaticServiceHubContextStore.Get(String connectionStringSetting) [2021-04-28T15:44:19.296Z] at Microsoft.Azure.WebJobs.Extensions.SignalRService.ServerlessHub..ctor(IServiceHubContext hubContext, IServiceManager serviceManager) [2021-04-28T15:44:19.301Z] at IOX.PlantDocs.Functions.SiteHub..ctor() [2021-04-28T15:44:19.302Z] --- End of stack trace from previous location --- [2021-04-28T15:44:19.304Z] at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.ConstructorMatcher.CreateInstance(IServiceProvider provider) [2021-04-28T15:44:19.306Z] at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.CreateInstance(IServiceProvider provider, Type instanceType, Object[] parameters) [2021-04-28T15:44:19.307Z] at Microsoft.Azure.Functions.Worker.DefaultFunctionActivator.CreateInstance(Type instanceType, FunctionContext context) in D:\a\1\s\src\DotNetWorker.Core\Invocation\DefaultFunctionActivator.cs:line 23 [2021-04-28T15:44:19.309Z] at Microsoft.Azure.Functions.Worker.Invocation.DefaultFunctionInvoker2.CreateInstance(FunctionContext context) in D:\a\1\s\src\DotNetWorker.Core\Invocation\DefaultFunctionInvoker.cs:line 26 [2021-04-28T15:44:19.310Z] at Microsoft.Azure.Functions.Worker.Invocation.DefaultFunctionExecutor.ExecuteAsync(FunctionContext context) in D:\a\1\s\src\DotNetWorker.Core\Invocation\DefaultFunctionExecutor.cs:line 27 [2021-04-28T15:44:19.313Z] at Microsoft.Azure.Functions.Worker.OutputBindings.OutputBindingsMiddleware.Invoke(FunctionContext context, FunctionExecutionDelegate next) in D:\a\1\s\src\DotNetWorker.Core\OutputBindings\OutputBindingsMiddleware.cs:line 13 [2021-04-28T15:44:19.315Z] at Microsoft.Azure.Functions.Worker.GrpcWorker.InvocationRequestHandlerAsync(InvocationRequest request, IFunctionsApplication application, IInvocationFeaturesFactory invocationFeaturesFactory, ObjectSerializer serializer, IOutputBindingsInfoProvider outputBindingsInfoProvider) in D:\a\1\s\src\DotNetWorker.Grpc\GrpcWorker.cs:line 166.

Please let me know how to configure this and if there is a demo and documentation for the isolated .net and SignalR.

Thank you.

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,248 questions
Azure SignalR Service
Azure SignalR Service
An Azure service that is used for adding real-time communications to web applications.
120 questions
0 comments No comments
{count} votes

Accepted answer
  1. Pramod Valavala 20,516 Reputation points Microsoft Employee
    2021-04-29T07:30:53.903+00:00

    @John Harris The ServerlessHub class is to react to messages coming up via SignalR but the negotiate call is still a simple HTTP request. This function alone must be separate since it is required before the connection is established. You can use the sample code in the docs as-is for most cases.

    0 comments No comments

0 additional answers

Sort by: Most helpful