I'm trying to read a number of performance counters from a running .NET 4 application, from another .NET 4 application.
Some counters, such as Process\% Processor Time
and Process\Private Bytes
work fine. However, as soon as I try to read a performance counter from one of the .NET categories, such as .NET CLR Memory\# Gen 0 Collections
, I get the following exception:
Instance 'MyApplication' does not exist in the specified Category
When I call:
new PerformanceCounterCategory(".NET CLR Memory").GetInstanceNames()
It returns a very small set of instances, and MyApplication is indeed not in the list. However, when I look at my performance counters in perfmon
, the list of instances I see there for the same category/counter is much longer and DOES include MyApplication.
Does anyone know why the .NET counters are not visible to my application?
(Note: The monitored application is started by the monitoring application, so they definitely run in the same user account. I also tried starting my monitoring application as Administrator and adding my account to the Performance Monitor Users group, to no effect.)