18

我在 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 框架 4.5。

这是堆栈跟踪

at System.Diagnostics.PerformanceCounter.InitializeImpl()

谢谢!

更新 我正在添加 Drew 要求的屏幕截图。 在此处输入图像描述

在此处输入图像描述

在此处输入图像描述

4

6 回答 6

27

因此,根据您提供的信息,很明显这些是当 SignalR 尝试创建性能计数器但无权使用进程运行的身份时抛出的第一次机会异常。您可以放心地忽略这些异常,但您显然不会获得性能计数器数据。

如果要创建性能计数器,则需要确保应用程序的标识在运行时属于 Performance Counter Users 组。要么,要么您需要使用Microsoft ASP.NET SignalR Utilities NuGet 包中提供的实用程序应用程序,它允许您创建带外计数器。只需安装软件包并运行命令:

signalr ipc
于 2013-07-10T03:31:41.310 回答
14

Drew Marsh 的回应,也为我解决了这个问题。以下是描述如何运行signalr命令的其他详细信息:


使用包管理器安装 SignalR Utils:

  1. 在 VS 中:工具 -> 库包管理器 -> 包管理器控制台
  2. 在命令行中,键入:

    下午>Install-Package Microsoft.AspNet.SignalR.Utils

  3. 以管理员身份运行 IDE,运行:

    下午>signalr ipc

运行性能计数器安装命令 ( ) 需要管理员权限signalr ipc- 不这样做运行会导致此错误:

错误:System.Security.SecurityException:不允许请求的注册表访问。在 Microsoft.Win32.RegistryKey.OpenSubKey(String name, Boolean writable) at System.Diagnostics.PerformanceCounterLib.CreateRegistryEntry(String categoryName, PerformanceCounterCategoryType categoryType, CounterCreationDataCollection creationData, Boolean& iniRegistered) at System.Diagnostics.PerformanceCounterLib.RegisterCategory(String category Name, PerformanceCounterCategoryType categoryType, String categoryHelp, Counter CreationDataCollection creationData) at System.Diagnostics.PerformanceCounterCategory.Create(String categoryName, String categoryHelp, PerformanceCounterCategoryType categoryType, CounterCreationDataCollection counterData) at Microsoft.AspNet.SignalR.Utils。

   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
于 2014-01-03T18:45:43.113 回答
3

请注意,如果您遵循上述(正确)建议并调用“signalr ipc”来安装 SignalR 的自定义计数器,则在使用调试器运行时,您的应用程序可能会莫名其妙地完全停止工作。问题是 CLR 在初始化时如何处理 CultureInfo 的错误。该问题至少存在于 SignalR 2.2.0 中。此处讨论了完整的解释和一些解决方法:https ://github.com/SignalR/SignalR/issues/3414

于 2016-06-29T02:26:24.057 回答
2

这是无法以管理员权限运行的开发人员的解决方案。创建下面的类并将其添加到 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;
}
于 2019-02-25T03:17:23.457 回答
0

如果您不想完全使用性能计数器,那么当您的解析器在被要求提供IPerformanceCounterManager.

https://github.com/SignalR/SignalR/blob/master/src/Microsoft.AspNet.SignalR.Core/Hosting/HostDependencyResolverExtensions.cs

    private static void InitializePerformanceCounters(this IDependencyResolver resolver, string instanceName, CancellationToken hostShutdownToken)
    {
        var counters = resolver.Resolve<IPerformanceCounterManager>();
        if (counters != null)
        {
            counters.Initialize(instanceName, hostShutdownToken);
        }
    }

我刚刚遇到了这个问题,因为 ninject 在它要求未配置的依赖项时抛出。

于 2021-02-02T16:24:32.067 回答
0

解决了这个问题。在我的测试或生产服务器中,我没有安装像 Visual Studio 这样的 IDE。所以我坚持同样的错误。最后我简单地做了以下步骤:

请在安装 VS 的服务器中执行以下步骤

  • 在 VS 中:工具 -> NuGet 包管理器 -> 包管理器控制台 在命令行中,键入:

  • 下午>Install-Package Microsoft.AspNet.SignalR.Utils

  • 转到包 -> Microsoft.AspNet.SignalR.Utils.2.2.3 -> 工具

  • 复制signalr.exe

请在测试或生产服务器中执行以下步骤

  • 在 bin -> debug 文件夹下粘贴 signalr.exe 并复制路径
  • 以管理员模式打开命令提示符并将目录更改为复制的路径
  • 键入并运行命令signalr.exe ipc

成功运行上述命令后,我启动了应用程序,它运行良好。如果他们在测试环境中需要它,我只是将其发布给其他人。

于 2018-04-21T12:15:00.967 回答