G
Guest
I am attempting to create a custom performance counter category for use by an
application I am developing. I have found, however, that after calling any of
several of the static PerformanceCounterCategory methods, the next attempt to
write to the Console fails with a System.IO.IOException (_message = "the
handle is invalid", _COMPlusExceptionCode = -532459699, _HResult =
-2147024890).
I am developing using Visual Studio 2003 v 7.1.3088 and .NET Framework v
1.1.4322 SP1.
The following code reliably reproduces the problem on my system:
try
{
Console.WriteLine("Beginning Performance Counter Installation Test");
if (PerformanceCounterCategory.Exists("testcategory"))
{
PerformanceCounterCategory.Delete("testcategory");
Console.WriteLine("Called Delete for existing performance category");
if (PerformanceCounterCategory.Exists("testcategory"))
Console.WriteLine("Performance category still exists!");
else
Console.WriteLine("Performance Category successfully deleted.");
}
else
Console.WriteLine("Category does not yet exist.");
CounterCreationData ccd = new CounterCreationData("testcounter",
"Test counter", PerformanceCounterType.NumberOfItems32);
CounterCreationDataCollection ccdc = new CounterCreationDataCollection();
ccdc.Add(ccd);
Console.WriteLine("Initialized counter creation data collection.");
PerformanceCounterCategory.Create("testcategory", "Test category", ccdc);
Console.WriteLine("Created category and counters");
PerformanceCounterCategory[] allCategories =
PerformanceCounterCategory.GetCategories();
Console.WriteLine("Retrieved all performance counter categories");
}
catch(Exception e)
{
int i = 1;
}
By commenting out various parts of the above code, I have established that
this problem occurs:
* In the PerformanceCounterCategory.Exists call, but only if the return
value was false (if the category _does_ exist, it's fine.
* In the PerformanceCounterCategory.Create call
* In the PerformanceCounterCategory.GetCategories call.
In all these cases, the PerformanceCounterCategory functions do actually
execute successfully - the correct value is returned, category is created and
categories are listed. It's only the next attempt to write to the standard
output that goes splat.
It looks a lot like something is closing the standard output stream... I
have tried redirecting the standard output to something other than the
console buffer, and got the same result.
A serious side-effect of the problem is that if you attempt to use
InstallUtil to run a PerformanceCounterInstaller, the IOException as
InstallUtil attempts to write to the console after actually performing the
installation causes the installation to be rolled back (even though the
counters _were_ actually successfully installed).
As an even better side effect: while using InstallUtil to run an installer
that included a ServiceInstaller, ServiceProcessInstaller and
PerformanceCounterInstaller, this exception tripped the debugger, then
somehow deleted half the CurrentControlSet entries in the registry
(everything before my custom performance category in the alphabet) during the
rollback. This quite effectively rendered my development machine so much junk
(vmware is your friend...).
So, does anyone have any insight to offer on this issue? I really don't want
to have to choose between my performance counters and my console output, much
less between the performance counters and the installation!
I have looked at the description for the KB830297 fix, but am uncertain as
to its applicability, since we have no J# code at all. Please help!
application I am developing. I have found, however, that after calling any of
several of the static PerformanceCounterCategory methods, the next attempt to
write to the Console fails with a System.IO.IOException (_message = "the
handle is invalid", _COMPlusExceptionCode = -532459699, _HResult =
-2147024890).
I am developing using Visual Studio 2003 v 7.1.3088 and .NET Framework v
1.1.4322 SP1.
The following code reliably reproduces the problem on my system:
try
{
Console.WriteLine("Beginning Performance Counter Installation Test");
if (PerformanceCounterCategory.Exists("testcategory"))
{
PerformanceCounterCategory.Delete("testcategory");
Console.WriteLine("Called Delete for existing performance category");
if (PerformanceCounterCategory.Exists("testcategory"))
Console.WriteLine("Performance category still exists!");
else
Console.WriteLine("Performance Category successfully deleted.");
}
else
Console.WriteLine("Category does not yet exist.");
CounterCreationData ccd = new CounterCreationData("testcounter",
"Test counter", PerformanceCounterType.NumberOfItems32);
CounterCreationDataCollection ccdc = new CounterCreationDataCollection();
ccdc.Add(ccd);
Console.WriteLine("Initialized counter creation data collection.");
PerformanceCounterCategory.Create("testcategory", "Test category", ccdc);
Console.WriteLine("Created category and counters");
PerformanceCounterCategory[] allCategories =
PerformanceCounterCategory.GetCategories();
Console.WriteLine("Retrieved all performance counter categories");
}
catch(Exception e)
{
int i = 1;
}
By commenting out various parts of the above code, I have established that
this problem occurs:
* In the PerformanceCounterCategory.Exists call, but only if the return
value was false (if the category _does_ exist, it's fine.
* In the PerformanceCounterCategory.Create call
* In the PerformanceCounterCategory.GetCategories call.
In all these cases, the PerformanceCounterCategory functions do actually
execute successfully - the correct value is returned, category is created and
categories are listed. It's only the next attempt to write to the standard
output that goes splat.
It looks a lot like something is closing the standard output stream... I
have tried redirecting the standard output to something other than the
console buffer, and got the same result.
A serious side-effect of the problem is that if you attempt to use
InstallUtil to run a PerformanceCounterInstaller, the IOException as
InstallUtil attempts to write to the console after actually performing the
installation causes the installation to be rolled back (even though the
counters _were_ actually successfully installed).
As an even better side effect: while using InstallUtil to run an installer
that included a ServiceInstaller, ServiceProcessInstaller and
PerformanceCounterInstaller, this exception tripped the debugger, then
somehow deleted half the CurrentControlSet entries in the registry
(everything before my custom performance category in the alphabet) during the
rollback. This quite effectively rendered my development machine so much junk
(vmware is your friend...).
So, does anyone have any insight to offer on this issue? I really don't want
to have to choose between my performance counters and my console output, much
less between the performance counters and the installation!
I have looked at the description for the KB830297 fix, but am uncertain as
to its applicability, since we have no J# code at all. Please help!