2

我有一个 .Net Core 3.0 控制台项目,其中包含 WebJob 函数,该函数具有与 Azure Signal R 的输出绑定。该应用程序构建正常,但是当我运行它并尝试通过 SignalR 发送消息时,我收到以下错误:

{System.MissingMethodException: Method not found: 'System.String Microsoft.Azure.SignalR.AuthenticationHelper.GenerateAccessToken(System.String, System.String, System.Collections.Generic.IEnumerable`1<System.Security.Claims.Claim>, System.TimeSpan, System.String)'.
at Microsoft.Azure.SignalR.Management.RestApiAccessTokenGenerator.Generate(String audience, Nullable`1 lifetime)
at Microsoft.Azure.SignalR.Management.RestApiProvider.GenerateRestApiEndpoint(String path, Nullable`1 lifetime)
at Microsoft.Azure.SignalR.Management.RestApiProvider.GetSendToGroupEndpoint(String groupName, Nullable`1 lifetime)
at Microsoft.Azure.SignalR.Management.RestHubLifetimeManager.SendGroupAsync(String groupName, String methodName, Object[] args, CancellationToken cancellationToken)
at Microsoft.AspNetCore.SignalR.Internal.GroupProxy`1.SendCoreAsync(String method, Object[] args, CancellationToken cancellationToken)
at Microsoft.Azure.WebJobs.Extensions.SignalRService.AzureSignalRClient.SendToGroup(String groupName, SignalRData data)
at Microsoft.Azure.WebJobs.Extensions.SignalRService.SignalRAsyncCollector`1.AddAsync(T item, CancellationToken cancellationToken)
at InSysWebJobP300DataProcessor.Helper.ProcessMinuteData(Message message, ConnectionMultiplexer redisConnection, IAsyncCollector`1 signalRMessages, ILogger log) in E:\InergySystems\GitHub\InSysCore\InSysWebJobP300DataProcessor\Helper.cs:line 125}

SignalR 服务在 Program.Main 中注册:

static void Main(string[] args)
{
    var builder = new HostBuilder();
    builder.ConfigureWebJobs(b =>
    {
        b.AddAzureStorageCoreServices();
        b.AddServiceBus().AddSignalR();
    });
    builder.ConfigureLogging((context, b) =>
    {
        b.ClearProviders();
        b.AddConfiguration(context.Configuration.GetSection("Logging"));
        if (context.HostingEnvironment.IsDevelopment())
        {
            b.AddConsole();
        }
    });

    var host = builder.Build();
    using (host)
    {
        host.Run();
    }
}

我有一个具有以下签名的函数:

[FunctionName("ProcessMinuteData")]
public async Task RunAsync([ServiceBusTrigger("data", Connection = "AzureWebJobsServiceBusConnection")]Message message, [SignalR(HubName = "insyshub")] IAsyncCollector<SignalRMessage> signalRMessages, ILogger log)

从服务总线接收到的消息处理得很好,但是尝试使用以下方法通过 SignalR 推出消息,会导致上述错误:

await signalRMessages.AddAsync(new SignalRMessage
{
    GroupName = "GroupName",
    Target = "targetMethod",
    Arguments = new[] { JsonConvert.SerializeObject(message) }
});

请注意,应用程序不需要通过 SignalR 接收消息,只需将它们推出即可。

我安装了以下 NuGet 包:

<PackageReference Include="Microsoft.AspNetCore.SignalR" Version="1.1.0" />
<PackageReference Include="Microsoft.Azure.SignalR" Version="1.2.1" />
<PackageReference Include="Microsoft.Azure.WebJobs" Version="3.0.14" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions" Version="3.0.5" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Http" Version="3.0.2" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.ServiceBus" Version="4.0.0" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.SignalRService" Version="1.0.2" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage" Version="3.0.10" />
<PackageReference Include="Microsoft.Azure.WebJobs.Logging.ApplicationInsights" Version="3.0.14" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="3.0.1" />
4

1 回答 1

8

似乎从 Microsoft.Azure.SignalR 1.2.0 开始,如果您想使用我在问题中详细使用的方法,您现在需要包含 Microsoft.Azure.SignalR.Management。

在 1.2.0 之前,您不需要包含 Microsoft.Azure.SignalR.Management。

于 2019-11-21T00:41:18.607 回答