The requested Performance Counter is not a custom counter, it has to be initialized as ReadOnly
Asked Answered
A

4

40

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.

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:

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?

Attentive answered 12/1, 2010 at 4:35 Comment(2)
I ran into that issue a long time ago and think I ended up just creating a custom counter for what I needed to do, so that's not helpful.. but I can say I wasn't having an issue with 32 v 64 bit in that instance, so it may not be worth it for you to chase that tail too long.Companion
Thanks Jim, I am starting to think that it would be quicker for me to pave the machine and reinstall x86 windows than to find a solution to this problem! Sad. But true.Attentive
S
56

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.

I find this happens to the .Net perf counters sometimes (no idea why) but using lodctr1 gets them back. If you indicate which perf counter you are trying to get at we might be able to give you more help.

  1. Note that the example lined is for .Net 1.1, adjust for different frameworks accordingly.
Shabby answered 17/1, 2010 at 17:52 Comment(5)
I am using .Net 4.0.30319. I tried using lodctr (used v4 settings) but problem still persists. I have uploaded a screenshot of my error message here: imgur.com/eJ4ukWaylin
+1. As of .NET 2.0 I get the same error message for a counter which does not exist.Corbitt
I have same issue like robasta. would you please suggest any other way, let us know if you required any other detail like event error log,Danelledanete
I received this error message in .Net 4.5 when some custom perf counters were missing. If you are installing customer counters, ensure they installed correctly. Close and reopen PerfMon to ensure they are there.Sassan
Yes, you need to add the CounterDataCollection first: PerformanceCounterCategory.Create(CategoryName, CategoryDescription, PerformanceCounterCategoryType.SingleInstance, counterDataCollection); you can see an example here: dotnetcodr.com/2014/11/18/…Barret
E
9

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.

I had to re-add them

lodctr /R
cd C:\Windows\Inf\.NETFramework
lodctr corperfmonsymbols.ini
Elope answered 25/1, 2013 at 1:26 Comment(1)
I had to first unload the performance counters by using unlodctr as described in the marked answer.Dissonancy
R
2

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

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).

Raffia answered 9/5, 2018 at 14:35 Comment(0)
B
0

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,

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 conducted and 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.

after checking ShuggyCoUk answer and other answers if you are still getting the error, My advice is to consider checking related async functions.

Bountiful answered 5/1, 2019 at 5:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.