我在AspNet MVC 4应用程序中使用SignalR 1.1.2版本和Windsor Castle。 我的问题是,自从我转移到较新的SignalR版本后,此错误消息显示出来。
"The requested Performance Counter is not a custom counter, it has to be initialized as ReadOnly."
在
行 RouteTable.Routes.MapHubs();
这是RegisterHubs类
public static class RegisterHubs
{
public static void Start()
{
var signalrDependencyContainer = new WindsorContainer().Install(new HubsInstaller());
var signalrDependency = new SignalrDependencyResolver(signalrDependencyContainer.Kernel);
GlobalHost.DependencyResolver = signalrDependency;
RouteTable.Routes.MapHubs();
}
}
我已经尝试了一些我在互联网上找到的东西,如:
lodctr /R
cd C:\Windows\Inf\.NETFramework
lodctr corperfmonsymbols.ini
但我仍然收到相同的错误消息。有任何想法吗?
我正在使用dotnet framework 4.5。
这是堆栈跟踪
at System.Diagnostics.PerformanceCounter.InitializeImpl()
谢谢!
更新 我正在添加Drew请求的屏幕截图。
答案 0 :(得分:24)
因此,根据您提供的信息,很明显,当SignalR尝试创建性能计数器时,这些是第一次机会异常,但是没有权利使用进程运行的标识来执行此操作下。您可以放心地忽略这些异常,但显然您无法获得性能计数器数据。
如果要创建性能计数器,则需要确保应用程序的标识在运行时属于Performance Counter Users组。要么您需要使用Microsoft ASP.NET SignalR Utilities NuGet package中提供的实用程序应用程序,它允许您在带外创建计数器。只需安装软件包并运行命令:
signalr ipc
答案 1 :(得分:14)
Drew Marsh's response,也解决了我的问题。以下是描述如何运行signalr
命令的其他详细信息:
使用包管理器安装SignalR Utils:
从命令行键入:
PM> Install-Package Microsoft.AspNet.SignalR.Utils
以管理员身份运行IDE,运行:
PM> signalr ipc
运行性能计数器安装命令(signalr ipc
)需要管理员权限 - 运行时不会导致此错误:
错误:System.Security.SecurityException:请求的注册表访问 不被允许。 at Microsoft.Win32.RegistryKey.OpenSubKey(String name,Boolean writable) 在System.Diagnostics.PerformanceCounterLib.CreateRegistryEntry(String categoryName,PerformanceCounterCategoryType categoryType,CounterCreationDataCollec 创建数据,布尔和& iniRegistered) 在System.Diagnostics.PerformanceCounterLib.RegisterCategory(String 类别 Name,PerformanceCounterCategoryType categoryType,String categoryHelp,Counter CreationDataCollection creationData) 在System.Diagnostics.PerformanceCounterCategory.Create(String categoryName, String categoryHelp,PerformanceCounterCategoryType categoryType, CounterCreationDataCollection counterData) 在Microsoft.AspNet.SignalR.Utils.PerformanceCounterInstaller.InstallCounters()
at Microsoft.AspNet.SignalR.Utils.InstallPerformanceCountersCommand.Execute( String[] args) at Microsoft.AspNet.SignalR.Utils.Program.Main(String[] args) The Zone of the assembly that failed was: MyComputer
答案 2 :(得分:3)
请注意,如果您遵循上述(正确)建议并调用“signalr ipc'要安装SignalR的自定义计数器,在使用调试器运行时,您的应用程序可能会莫名其妙地完全停止工作。 问题是CLR在初始化时如何处理CultureInfo的错误。问题至少存在于SignalR 2.2.0中。 这里将讨论完整的解释和几个解决方法:https://github.com/SignalR/SignalR/issues/3414
答案 3 :(得分:0)
解决了这个问题。在我的测试或生产服务器中,我没有安装在其中的Visual Studio这样的IDE。所以我坚持同样的错误。最后我简单地完成了以下步骤:
请按照安装VS的服务器中的以下步骤进行操作
在VS中:工具 - > NuGet包管理器 - >包管理器控制台 从命令行键入:
PM> Install-Package Microsoft.AspNet.SignalR.Utils
转到包裹 - > Microsoft.AspNet.SignalR.Utils.2.2.3 - >工具
复制signalr.exe
请按照测试或生产服务器中的以下步骤进行操作
signalr.exe ipc
成功运行上面的命令后,我启动了它运行良好的应用程序。如果他们在测试环境中需要它,我刚刚发布给其他人。
答案 4 :(得分:0)
这是无法使用管理员权限运行的开发人员的解决方案。在下面创建类,然后将其添加到DependencyResolver中:
// Stop exception being thrown when trying to access performance counters
var dummyPerformanceCounterManager = new DummyPerformanceCounterManager();
GlobalHost.DependencyResolver.Register(
typeof(IPerformanceCounterManager),
() =>dummyPerformanceCounterManager);
这里是替换PerformanceCounterManager的类
public class DummyPerformanceCounterManager : IPerformanceCounterManager
{
private readonly static PropertyInfo[] _counterProperties = GetCounterPropertyInfo();
private readonly static IPerformanceCounter _noOpCounter = new NoOpPerformanceCounter();
public DummyPerformanceCounterManager()
{
foreach (var property in _counterProperties)
{
property.SetValue(this, new NoOpPerformanceCounter(), null);
}
}
public void Initialize(string instanceName, CancellationToken hostShutdownToken)
{
}
public IPerformanceCounter LoadCounter(string categoryName, string counterName, string instanceName, bool isReadOnly)
{
return _noOpCounter;
}
internal static PropertyInfo[] GetCounterPropertyInfo()
{
return typeof(DummyPerformanceCounterManager)
.GetProperties()
.Where(p => p.PropertyType == typeof(IPerformanceCounter))
.ToArray();
}
public IPerformanceCounter ConnectionsConnected { get; set; }
public IPerformanceCounter ConnectionsReconnected { get; set; }
public IPerformanceCounter ConnectionsDisconnected { get; set; }
public IPerformanceCounter ConnectionsCurrentForeverFrame { get; private set; }
public IPerformanceCounter ConnectionsCurrentLongPolling { get; private set; }
public IPerformanceCounter ConnectionsCurrentServerSentEvents { get; private set; }
public IPerformanceCounter ConnectionsCurrentWebSockets { get; private set; }
public IPerformanceCounter ConnectionsCurrent { get; private set; }
public IPerformanceCounter ConnectionMessagesReceivedTotal { get; private set; }
public IPerformanceCounter ConnectionMessagesSentTotal { get; private set; }
public IPerformanceCounter ConnectionMessagesReceivedPerSec { get; private set; }
public IPerformanceCounter ConnectionMessagesSentPerSec { get; private set; }
public IPerformanceCounter MessageBusMessagesReceivedTotal { get; private set; }
public IPerformanceCounter MessageBusMessagesReceivedPerSec { get; private set; }
public IPerformanceCounter ScaleoutMessageBusMessagesReceivedPerSec { get; private set; }
public IPerformanceCounter MessageBusMessagesPublishedTotal { get; private set; }
public IPerformanceCounter MessageBusMessagesPublishedPerSec { get; private set; }
public IPerformanceCounter MessageBusSubscribersCurrent { get; private set; }
public IPerformanceCounter MessageBusSubscribersTotal { get; private set; }
public IPerformanceCounter MessageBusSubscribersPerSec { get; private set; }
public IPerformanceCounter MessageBusAllocatedWorkers { get; private set; }
public IPerformanceCounter MessageBusBusyWorkers { get; private set; }
public IPerformanceCounter MessageBusTopicsCurrent { get; private set; }
public IPerformanceCounter ErrorsAllTotal { get; private set; }
public IPerformanceCounter ErrorsAllPerSec { get; private set; }
public IPerformanceCounter ErrorsHubResolutionTotal { get; private set; }
public IPerformanceCounter ErrorsHubResolutionPerSec { get; private set; }
public IPerformanceCounter ErrorsHubInvocationTotal { get; private set; }
public IPerformanceCounter ErrorsHubInvocationPerSec { get; private set; }
public IPerformanceCounter ErrorsTransportTotal { get; private set; }
public IPerformanceCounter ErrorsTransportPerSec { get; private set; }
public IPerformanceCounter ScaleoutStreamCountTotal { get; private set; }
public IPerformanceCounter ScaleoutStreamCountOpen { get; private set; }
public IPerformanceCounter ScaleoutStreamCountBuffering { get; private set; }
public IPerformanceCounter ScaleoutErrorsTotal { get; private set; }
public IPerformanceCounter ScaleoutErrorsPerSec { get; private set; }
public IPerformanceCounter ScaleoutSendQueueLength { get; private set; }
}
internal class NoOpPerformanceCounter : IPerformanceCounter
{
public string CounterName => GetType().Name;
public long Decrement() => 0;
public long Increment() => 0;
public long IncrementBy(long value) => 0;
public long RawValue { get; set; } = 0;
public void Close() { }
public void RemoveInstance() { }
CounterSample IPerformanceCounter.NextSample() => CounterSample.Empty;
}
答案 5 :(得分:0)
如果您不想完全使用性能计数器,那么当您的解析器在请求 IPerformanceCounterManager
时返回“null”是完全没问题的。
private static void InitializePerformanceCounters(this IDependencyResolver resolver, string instanceName, CancellationToken hostShutdownToken)
{
var counters = resolver.Resolve<IPerformanceCounterManager>();
if (counters != null)
{
counters.Initialize(instanceName, hostShutdownToken);
}
}
我刚刚遇到了这个问题,因为 ninject 在要求未配置的依赖项时抛出。