.Net 2.0, PerformanceCounter.NextValue() exceptions

J

Joe K

I recently ported some code that retrieves performance data using
performance counters from .Net 1.1 and .Net 2.0. I intermitently receive
one of the three exceptions when calling NextValue() on a PerformanceCounter
object. As you can see, each of the underlying exceptions occurs within
native code within the .Net 2.0 framework. In all cases it appears as
though the underlying registry key within .Net has been forcibly closed from
underneath the object. The issue is reproducible across multiple systems,
so it is not configuration related. It does however require multiple
threads to reproduce (although each thread creates, uses and closes its own
PerformanceCounter object, so there is NO sharing of resources between the
threads).

Anyone see this and have any insight as to the cause? It seems like an
object being used by .Net is being forcibly closed or GCed from underneath
it. The same code in .Net 1.1 runs in the same test without a problem.

Thanks in advance.



*** Exception #1***
(RemoteExceptionType: System.ArgumentNullException)

System.ArgumentNullException : SafeHandle cannot be null.
[Flags=1]
RemoteStackTrace:
at Microsoft.Win32.Win32Native.RegQueryValueEx(SafeRegistryHandle hKey,
String lpValueName, Int32[] lpReserved, Int32& lpType, Byte[] lpData, Int32&
lpcbData)
at Microsoft.Win32.RegistryKey.InternalGetValue(String name, Object
defaultValue, Boolean doNotExpand, Boolean checkSecurity)
at Microsoft.Win32.RegistryKey.GetValue(String name)
at System.Diagnostics.PerformanceMonitor.GetData(String item)
at System.Diagnostics.PerformanceCounterLib.GetPerformanceData(String
item)
at System.Diagnostics.PerformanceCounterLib.GetCategorySample(String
category)
at System.Diagnostics.PerformanceCounterLib.GetCategorySample(String
machine, String category)
at System.Diagnostics.PerformanceCounter.NextSample()
at System.Diagnostics.PerformanceCounter.NextValue()
at MyCode.Monitoring.PerfCounterInstanceResult.Sample() in
c:\sandbox\mycode\MyCode.cs:line 407

*** Exception #2 ***
(RemoteExceptionType: System.ObjectDisposedException)

System.ObjectDisposedException : Cannot access a closed registry key.
Object name: 'HKEY_PERFORMANCE_DATA'.
[Flags=1]
RemoteStackTrace:
at System.ThrowHelper.ThrowObjectDisposedException(String objectName,
ExceptionResource resource)
at Microsoft.Win32.RegistryKey.InternalGetValue(String name, Object
defaultValue, Boolean doNotExpand, Boolean checkSecurity)
at Microsoft.Win32.RegistryKey.GetValue(String name)
at System.Diagnostics.PerformanceMonitor.GetData(String item)
at System.Diagnostics.PerformanceCounterLib.GetPerformanceData(String
item)
at System.Diagnostics.PerformanceCounterLib.GetCategorySample(String
category)
at System.Diagnostics.PerformanceCounterLib.GetCategorySample(String
machine, String category)
at System.Diagnostics.PerformanceCounter.NextSample()
at System.Diagnostics.PerformanceCounter.NextValue()
at MyCode.Monitoring.PerfCounterInstanceResult.Sample() in
c:\sandbox\mycode\MyCode.cs:line 407

*** Exception #3 ***
(RemoteExceptionType: System.NullReferenceException)

System.NullReferenceException : Object reference not set to an instance of
an object.
[Flags=1]
RemoteStackTrace:
at Microsoft.Win32.RegistryKey.Win32Error(Int32 errorCode, String str)
at Microsoft.Win32.RegistryKey.InternalGetValue(String name, Object
defaultValue, Boolean doNotExpand, Boolean checkSecurity)
at Microsoft.Win32.RegistryKey.GetValue(String name)
at System.Diagnostics.PerformanceMonitor.GetData(String item)
at System.Diagnostics.PerformanceCounterLib.GetPerformanceData(String
item)
at System.Diagnostics.PerformanceCounterLib.GetCategorySample(String
category)
at System.Diagnostics.PerformanceCounterLib.GetCategorySample(String
machine, String category)
at System.Diagnostics.PerformanceCounter.NextSample()
at System.Diagnostics.PerformanceCounter.NextValue()
at MyCode.Monitoring.PerfCounterInstanceResult.Sample() in
c:\sandbox\mycode\MyCode.cs:line 407
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top