gpt4 book ai didi

通过 Nuget 更新后出现 SignalR 2.0 错误

转载 作者:行者123 更新时间:2023-12-01 03:53:06 25 4
gpt4 key购买 nike

我已在 ASPNET MVC 4.0 应用程序中将 SignalR 更新为 2.0,现在我收到以下错误:

计数器 'Message Bus Messages Published Total' 在指定的类别中不存在

错误被抛出

app.MapSignalR();

这是我现在在 Startup 类中使用的代码(之前我使用过 RegisterHubs。
public static class Startup
{
public static void Configuration(IAppBuilder app)
{
var signalrDependencyContainer = new WindsorContainer().Install(new HubsInstaller());
var signalrDependency = new SignalrDependencyResolver(signalrDependencyContainer.Kernel);
GlobalHost.DependencyResolver = signalrDependency;
app.MapSignalR();
}
}

更新

这是根据要求提取的部分代码。

这是我在安装计数器时得到的
PM> signalr ipc
SignalR Utility Version: 1.1.0.0
Installing performance counters...
Connections Connected
Connections Reconnected
Connections Disconnected
Connections Current
Connection Messages Received Total
Connection Messages Sent Total
Connection Messages Received/Sec
Connection Messages Sent/Sec
Message Bus Messages Received Total
Message Bus Messages Received/Sec
Scaleout Message Bus Messages Received/Sec
Messages Bus Messages Published Total
Messages Bus Messages Published/Sec
Message Bus Subscribers Current
Message Bus Subscribers Total
Message Bus Subscribers/Sec
Message Bus Allocated Workers
Message Bus Busy Workers
Message Bus Topics Current
Errors: All Total
Errors: All/Sec
Errors: Hub Resolution Total
Errors: Hub Resolution/Sec
Errors: Hub Invocation Total
Errors: Hub Invocation/Sec
Errors: Tranport Total
Errors: Transport/Sec
Scaleout Streams Total
Scaleout Streams Open
Scaleout Streams Buffering
Scaleout Errors Total
Scaleout Errors/Sec
Scaleout Send Queue Length

Performance counters installed!

StartupOwin.cs
using org.app.Ui.Web.App_Start;
using Microsoft.Owin;
[assembly: OwinStartup(typeof(StartupOwin), "Configuration")]
namespace org.app.Ui.Web.App_Start
{
using Owin;

public class StartupOwin
{
public void Configuration(IAppBuilder app)
{
org.app.Ui.Web.App_Start.StartupSignalR.ConfigureSignalR(app);
}
}
}

StartupSignalR.cs
namespace org.app.Ui.Web.App_Start
{
using Castle.Windsor;
using org.app.Ui.Web.Infrastructure;
using Microsoft.AspNet.SignalR;
using Owin;

public static class StartupSignalR
{
public static void ConfigureSignalR(IAppBuilder app)
{
app.MapSignalR(new HubConfiguration
{
Resolver = new SignalrDependencyResolver(
new WindsorContainer()
.Install(new HubsInstaller()).Kernel)
});
}
}
}

HubNewHandler.cs
namespace org.app.Ui.Web.Hubs
{
using System;
using System.Data.Entity;
using System.Data.Entity.Core.Objects;
using System.Linq;
using System.Timers;

using Castle.MicroKernel;
using Castle.MicroKernel.Lifestyle;
using Castle.Windsor;
using org.app.Data.Contracts;
using org.app.Data.Model;

using Microsoft.AspNet.SignalR;

public class HubNewHandler : IHubNewHandler
{
private System.Timers.Timer aTimer;
private DateTime lastDate = DateTime.UtcNow;
readonly private IKernel kernel;

public HubNewHandler(IKernel kernel)
{
this.kernel = kernel;
}

public void StartTimer()
{
aTimer = new System.Timers.Timer(10000);
aTimer.Elapsed += new ElapsedEventHandler(SendNewMessage);
aTimer.Enabled = true;
GC.KeepAlive(aTimer);
}

public void SendNewMessage(object state, ElapsedEventArgs elapsedEventArgs)
{
using (kernel.BeginScope())
{
var gdpUow = kernel.Resolve<IGdpUow>();

var gdpTesisConfigurationsRecord = gdpUow.GdpConfigurations.GetByPredicate(a => a.Description.Equals("LastDateTimeMessagesCheck")).SingleOrDefault();

if (gdpTesisConfigurationsRecord == null)
{
gdpTesisConfigurationsRecord = new GdpConfiguration
{
Description = "LastDateTimeMessagesCheck",
DateTimeValue = DateTime.Now.ToUniversalTime()
};
gdpUow.GdpConfigurations.Add(gdpTesisConfigurationsRecord);
}

var lastMessagesDateTimeCheck = gdpTesisConfigurationsRecord.DateTimeValue;
var messagesList = GetShowableMessagesList(gdpUow, lastMessagesDateTimeCheck);

// Get a hub context for ServerHub
var serverHub = GlobalHost.ConnectionManager.GetHubContext<ServerHub>();

// Send a message to all the clients
serverHub.Clients.All.addNewMessagesToMap(messagesList, false);

gdpTesisConfigurationsRecord.DateTimeValue = elapsedEventArgs.SignalTime.ToUniversalTime();
gdpUow.GdpConfigurations.Update(gdpTesisConfigurationsRecord);
gdpUow.Commit();
}
}
}
}

ServerHub.cs
namespace org.app.Ui.Web.Hubs
{
using System;
using System.Linq;
using System.Threading.Tasks;
using Data.Contracts;
using Data.Model;
using Microsoft.AspNet.SignalR;

public class ServerHub : Hub
{
public IGdpUow Uow { get; set; }

public override Task OnConnected()
{
var connectionId = Guid.Parse(Context.ConnectionId);
return base.OnConnected();
}

public override Task OnDisconnected()
{
var connectionId = Guid.Parse(Context.ConnectionId);
return base.OnDisconnected();
}

public override Task OnReconnected()
{
var connectionId = Guid.Parse(Context.ConnectionId);
return base.OnReconnected();
}

public void GetAllMessages()
{
var messagesList = Uow.Messages.GetAll();
Clients.All.addNewMessagesToMap(messagesList, true);
}
}
}

任何想法可能是什么问题?
提前致谢。吉列尔莫。

最佳答案

尝试安装不同版本的 Microsoft.AspNet.SignalR.Utils。安装 1.1.2 版的 utils 后出现此错误。我卸载了它,并安装了 2.1.1 版:

Install-Package microsoft.aspnet.SignalR.Utils -version 2.1.1

然后我再次运行命令:
signalr.exe ipc

最后,我重新启动了我的应用程序并且它起作用了。问题似乎是一个版本使用“ 消息总线消息发布总数”而另一个版本使用“ 消息总线消息发布总数”(注意“消息”中缺少“s” “在第二个)。 See more information here (how's your Korean?)

关于通过 Nuget 更新后出现 SignalR 2.0 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20256675/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com