.NET 4.0 和 .NET 4.0 上的性能计数器视窗7

发布于 2024-08-07 02:25:48 字数 1076 浏览 1 评论 0原文

我有一个程序在 VS2008Vista 上运行良好,但我正在 Windows 7VS2010 上尝试它> / .NET Framework 4.0 并且它不起作用。最终的问题是 System. Diagnostics.PerformanceCounterCategory.GetCategories()(和其他 PerformanceCounterCategory 方法)不起作用。我正在关注:

System.InvalidOperationException 并显示消息“无法加载计数器名称数据,因为从注册表中读取了无效索引 ''。”

我可以使用如下所示的非常简单的程序来重现这一点:

class Program
{
    static void Main(string[] args)
    {
        foreach (var pc in System.Diagnostics.PerformanceCounterCategory.GetCategories())
        {
            Console.WriteLine(pc.CategoryName);
        }
    }
}

我确实确保我以管理员身份运行该程序。我是否在附加 VS/调试器的情况下运行它并不重要。我没有另一台装有 Windows 7VS2010 的机器来测试它,所以我不确定哪一个使事情变得复杂(或两者兼而有之?)。它是 Windows 7 x64,我尝试强制该应用在 x32x64 中运行,但得到了相同的结果。

I have a program that works fine on VS2008 and Vista, but I'm trying it on Windows 7 and VS2010 / .NET Framework 4.0 and it's not working. Ultimately the problem is that System.Diagnostics.PerformanceCounterCategory.GetCategories() (and other PerformanceCounterCategory methods) is not working. I'm getting following:

System.InvalidOperationException with the message "Cannot load Counter Name data because an invalid index '' was read from the registry."

I can reproduce this with the very simple program shown below:

class Program
{
    static void Main(string[] args)
    {
        foreach (var pc in System.Diagnostics.PerformanceCounterCategory.GetCategories())
        {
            Console.WriteLine(pc.CategoryName);
        }
    }
}

I did make sure I'm running the program as an admin. It doesn't matter if I run it with VS/Debugger attached or not. I don't have another machine with Windows 7 or VS2010 to test it on, so I'm not sure which is complicating things here (or both?). It is Windows 7 x64 and I've tried forcing the app to run in both x32 and x64 but get the same results.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

过去的过去 2024-08-14 02:25:48

我的系统上的性能计数器似乎已损坏。虽然我没有完全遵循这篇文章,它引导我找到了解决方案。这就是我所做的:

在具有管理员/提升权限的命令提示符中键入以下内容:

lodctr /?

有用的东西...

然后键入:

lodctr /R

根据上一步中的文档,这将使 Windows 重建性能注册表字符串以及基于当前注册表设置和备份 INI 文件的从头开始的信息。我有一种感觉,这就是神奇之处。然而,接下来我注意到 .NET 性能计数器不再存在,因此基于 this 我输入了以下内容来重新加载它们:

lodctr "C:\Windows\Microsoft.NET\Framework64\v4.0.20506\corperfmonsymbols.ini"

请注意,此路径适用于 x64 上的 .NET Framework 4.0。您可以想象框架/平台的其他变体的路径。我猜测您应该始终从已安装的.NET 框架的最高版本加载计数器,但这只是猜测。

我希望这有一天能对其他人有所帮助!

It seems performance counters were corrupted on my system. Although I didn't follow this post exactly, it led me to the solution. Here is what I did:

In an command prompt with administrator/elevate privileges typed the following:

lodctr /?

Useful stuff in there...

Then typed:

lodctr /R

According to the docs from the prior step, this gets windows to rebuild the perf registry strings and info from scratch based on the current registry settings and backup INI files. I have a feeling this is what did the magic. However, next I noticed the .NET performance counters were not there anymore so based on this I typed the following to reload them:

lodctr "C:\Windows\Microsoft.NET\Framework64\v4.0.20506\corperfmonsymbols.ini"

Note that this path is for .NET Framework 4.0 on x64. You can imagine the path for other variations of the framework/platform. I'm guessing you should always load the counters from the highest version of the .NET framework that you have installed, but that is just a guess.

I hope this helps someone else someday!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文