.net 请求的性能计数器不是自定义计数器,它必须初始化为只读
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2046741/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
The requested Performance Counter is not a custom counter, it has to be initialized as ReadOnly
提问by Andrew Matthews
I am getting repeated errors about the ReadOnly property on performance counters whenever I try to debug a .NET windows service app. This app works fine on x86 windows vista, or x86 windows 2003. It's just stopped working on my new 64bit dev machine.
每当我尝试调试 .NET Windows 服务应用程序时,我都会收到有关性能计数器上的 ReadOnly 属性的重复错误。这个应用程序在 x86 windows vista 或 x86 windows 2003 上运行良好。它只是在我的新 64 位开发机器上停止工作。
I've run the relevant InstallUtil invocations on 64bit and 32bit command line VCVARS.bat, in admin mode. I get no errors setting up the category and each perf counter. But, regardless of whether I set the perf ctrs as readonly or not, I get this:
我已经在 64 位和 32 位命令行 VCVARS.bat 上以管理员模式运行了相关的 InstallUtil 调用。我在设置类别和每个性能计数器时没有遇到任何错误。但是,无论我是否将 perf ctrs 设置为只读,我都会得到:
The requested Performance Counter is not a custom counter, it has to be initialized as ReadOnly.
请求的性能计数器不是自定义计数器,它必须初始化为只读。
UPDATE
更新
I re-installed the machine with a 32bit version of Windows 7, and bizarrely I still get this error. The only thing that has changed is moving from Windows Vista Business to Windows 7 Professional. Does this ring any bells?
我用 32 位版本的 Windows 7 重新安装了机器,但奇怪的是我仍然收到此错误。唯一改变的是从 Windows Vista Business 迁移到 Windows 7 Professional。这是否敲响了警钟?
回答by ShuggyCoUk
This is due to the performance counter (or category) not existing, but with a horrible error message.
这是由于性能计数器(或类别)不存在,但带有可怕的错误消息。
Take a look in perfmon for the counter, it should be missing on the relevant machines.
在 perfmon 中查看计数器,它应该在相关机器上丢失。
I find this happens to the .Net perf counters sometimes (no idea why) but using lodctr1gets them back. If you indicate which perf counter you are trying to get at we might be able to give you more help.
我发现这种情况有时会发生在 .Net perf 计数器上(不知道为什么),但使用 lodctr 1将它们取回。如果您指出您要使用哪个性能计数器,我们或许可以为您提供更多帮助。
- Note that the example lined is for .Net 1.1, adjust for different frameworks accordingly.
- 请注意,内衬的示例适用于 .Net 1.1,请相应地针对不同的框架进行调整。
回答by Daniel Little
I ran into a variant of this issue, while I could see the .net performance counter tab in reflector it actually had no counters in it.
我遇到了这个问题的一个变体,虽然我可以在反射器中看到 .net 性能计数器选项卡,但它实际上没有计数器。
lodctr /R
cd C:\Windows\Inf\.NETFramework
lodctr corperfmonsymbols.ini
回答by Mateusz Moska
I've spent good few hours on that issue, following all the instructions found on the web, so I've decided to share my solution, maybe it will save some time for the others. Finally I got a hint under one of the link in comments:
我已经按照网上的所有说明在这个问题上花了好几个小时,所以我决定分享我的解决方案,也许它会为其他人节省一些时间。最后,我在评论中的一个链接下得到了一个提示:
You'll need to run Visual Studio as an administrator
您需要以管理员身份运行 Visual Studio
My app is using MassTrasit with RabbitMQ, and it was failing on sending messages to the queue. Apparently it adds some perf counters under the hood and it was failing without Admin privileges with that very descriptive error. Funny thing you will need to run it as admin only first time (that's what deceived me).
我的应用程序将 MassTrasit 与 RabbitMQ 结合使用,但未能将消息发送到队列。显然,它在幕后添加了一些性能计数器,并且在没有管理员权限的情况下失败,并出现非常描述性的错误。有趣的是,您只需要第一次以管理员身份运行它(这就是欺骗我的原因)。
回答by Saeed Mousavi
I was getting this misleading error on my deployment machine, I was catching the error using FirstChanceException Mechanism, The IIS was repeatedly stopping the related Application Pool after occurring this error and I was getting the 'Service Unavailable' error when calling the site,
我在部署机器上遇到了这个误导性错误,我使用 FirstChanceException 机制捕获了错误,发生此错误后 IIS 反复停止相关的应用程序池,并且在调用站点时出现“服务不可用”错误,
I tried many days to stop the counters or find/add the related counters but it did not work.
我尝试了很多天来停止计数器或查找/添加相关计数器但它没有用。
So I installed the VS on the server and debugged and noticed that I have been calling a non awaitable Linq query inside a async action which is not correctly conductedand accordingly there is a bug in application threading , and when there is many site visitors this bug shows up and IIS throws this exception and stops working.
因此,我在服务器上安装了 VS 并进行了调试,并注意到我一直在未正确执行的异步操作中调用不可等待的 Linq 查询,因此应用程序线程中存在错误,并且当有很多站点访问者时此错误出现并且 IIS 抛出此异常并停止工作。
after checking ShuggyCoUk answer and other answers if you are still getting the error, My advice is to consider checking related async functions.
检查 ShuggyCoUk 答案和其他答案后,如果您仍然收到错误,我的建议是考虑检查相关的异步功能。

