We are trying to create a custom performance counter and category in .Net 1.1 with Windows 2003 and XP as our operating systems. We use the following code to do this
if (PerformanceCounterCategory.Exists(categoryName)
PerformanceCounterCategory.Delete(categoryName)
CounterCreationData ccd = new CounterCreationData(counterName, counterHelp, PerformanceCounterType.RateOfCountsPerSecond32)
CounterCreationDataCollection ccdc = new CounterCreationDataCollection()
ccdc.Add(ccd)
PerformanceCounterCategory perfCategory = PerformanceCounterCategory.Create(categoryName, categoryHelp, ccdc)
OurLibrary.Error.AssertThrow(perfCategory.CounterExists(counterName), String.Format("Expected \"{0}\" counter to exist.", counterName))
PerformanceCounter counter = new PerformanceCounter(categoryName, counterName, false)
We get a "Category does not exist" InvalidOperationException when we assert that the counter exists. perfCategory != null at this time. The PerformanceCounterCategory.Create does NOT throw. We have tried many permutations of calls to try to get this to work, but it always throws. The odd thing is that the category and counter are actually created in the perfmon utility. We can see them from .net too, but not in the process that created them. We have tried this same code on Windows 2000 boxes and it works correctly. What is the problem with the Windows 2003 and XP operating systems that cause this to fail? We have searched the newsgroups and have not seen any explanations and very few instances of this problem. Are we the only ones using the .net performance counters
Thanks
Frank
Gary Chang - 22 May 2004 08:30 GMT
Hi Frank,
Currently I am looking for somebody who could help you on it. We will reply
here with more information as soon as possible.
If you have any more concerns on it, please feel free to post here.
Thanks for your understanding!
Best regards,
Gary Chang
Microsoft Online Partner Support

Signature
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
"Jeffrey Tan[MSFT]" - 24 May 2004 10:50 GMT
Hi Frank,
Based on my understanding, when you use PerformanceCounterCategory to
create categroy, you got "Category does not exist"
InvalidOperationException.
Is your application winform/console application? Or does it run under
Asp.net account?
If it is a winform/console application, what account does it run under? Is
the account administrator?
There is a useful information relate this by "Ryan Byington [MS]", please
refer to:
http://groups.google.com/groups?q=%22Category+does+not+exist%22+PerformanceC
ounter&hl=zh-CN&lr=&ie=UTF-8&selm=po%23jTWyGEHA.3800%40cpmsftngxa06.phx.gbl&
rnum=4
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.
Best regards,
Jeffrey Tan
Microsoft Online Partner Support

Signature
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
Frank Jones - 24 May 2004 22:26 GMT
This application is being run in NUnit, so it is effectively under the logged in user accounts security context. I am logged in as a local administrator, so it is not a security issue. I have run the test with registry and NTFS security auditing turned on and get no security errors there
No, we don't get a "Category does not exist" exception when creating the category. Only when trying to do something with it. The Create() call works fine. It's the assertion that the counter exists in the category that throws the exception
The most odd thing about this is that the category and counter (which is created through the CounterCreationData) really are created. It's just that in code at runtime, we cannot access the counter or category directly after it's been created. The test fails, then upon next run, it succeeds because the counter and category are both there
Fran
----- "Jeffrey Tan[MSFT]" wrote: ----
Hi Frank
Based on my understanding, when you use PerformanceCounterCategory to
create categroy, you got "Category does not exist"
InvalidOperationException.
Is your application winform/console application? Or does it run under
Asp.net account
If it is a winform/console application, what account does it run under? Is
the account administrator
There is a useful information relate this by "Ryan Byington [MS]", please
refer to
http://groups.google.com/groups?q=%22Category+does+not+exist%22+Performance
ounter&hl=zh-CN&lr=&ie=UTF-8&selm=po%23jTWyGEHA.3800%40cpmsftngxa06.phx.gbl
rnum=
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance
Best regards
Jeffrey Ta
Microsoft Online Partner Suppor
Get Secure! - www.microsoft.com/securit
This posting is provided "as is" with no warranties and confers no rights
"Jeffrey Tan[MSFT]" - 25 May 2004 10:48 GMT
Hi Frank,
Thanks very much for your feedback.
Yes, I have reproduced out your issue on my WindowXP and Windows 2003
machines.
After do some research, I found that this is a know issue of our product.
It looks like after creating the performance counter category we keep
around some shared information that is stale so we think that the Category
does not exist. The workaround is call
PerformanceCounter.CloseSharedResources() static method to refresh the
stale data and it should fix this issue.
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.
Best regards,
Jeffrey Tan
Microsoft Online Partner Support

Signature
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.