Error - Input string was not in a correct format

May 27, 2008 at 7:55 PM
Edited May 27, 2008 at 8:55 PM
greetings,

i'm trying to run your sample app WorkItemGroupDemo and am getting the above error after the init code is run for each of the performance counters- 
            ((System.ComponentModel.ISupportInitialize)(this.pcActiveThreads)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.pcInUseThreads)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.pcQueuedWorkItems)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.pcCompletedWorkItems)).EndInit();

 a trace shows this for the pcActiveThreads-

System.FormatException was unhandled
  Message="Input string was not in a correct format."
  Source="mscorlib"
  StackTrace:
       at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
       at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
       at System.Int32.Parse(String s, IFormatProvider provider)
       at System.Diagnostics.PerformanceCounterLib.GetStringTable(Boolean isHelp)
       at System.Diagnostics.PerformanceCounterLib.get_NameTable()
       at System.Diagnostics.PerformanceCounterLib.get_CategoryTable()
       at System.Diagnostics.PerformanceCounterLib.CounterExists(String category, String counter, Boolean& categoryExists)
       at System.Diagnostics.PerformanceCounterLib.CounterExists(String machine, String category, String counter)
       at System.Diagnostics.PerformanceCounter.Initialize()
       at System.Diagnostics.PerformanceCounter.EndInit()
       at WorkItemsGroupDemo.Form1.InitializeComponent() in E:\Downloads.Net\SmartThreadPool\smartthreadpool-11703\WorkItemsGroup Demo VB\Form1.Designer.vb:line 1025
       at WorkItemsGroupDemo.Form1..ctor() in E:\Downloads.Net\SmartThreadPool\smartthreadpool-11703\WorkItemsGroup Demo VB\Form1.vb:line 50
       at WorkItemsGroupDemo.Program.Main() in E:\Downloads.Net\SmartThreadPool\smartthreadpool-11703\WorkItemsGroup Demo VB\Program.vb:line 17

i've googled the above but can't seem to diagnose the problem.  i found results for correcting reg entries, but nothing that would apply to custom counters.  Any help would be appreciated.

i did convert the sample to VB, but the same happens in the C# version.  i have not tried to run on another system.

thx,

jim
Coordinator
May 28, 2008 at 5:45 AM
Hi Jim,

This may happen if you ran an old version of the SmartThreadPool (older than the one in the CodeProject).
The Performance Counters were changed.

To overcome this run the TestSmartThreadPool demo once.
It will delete the old Performance Counters and create the new ones.


Regards,
Ami
May 28, 2008 at 2:15 PM

Ami,

I did review the other sample & saw the code/comment about PerfomanceCounter issues.  I did try to run this sample and it caused an exception at
   if (!PerformanceCounterCategory.Exists("SmartThreadPool"))
the exception was
"Input string was not in a correct format."
and the other details-
Make sure your method formats are in the right format.
When converting a string to date time ...

I also tried the sample on a VISTA machine and it ran fine.  I'm developing on an XP SP2.

Thanks,

Jim

Coordinator
May 28, 2008 at 2:37 PM
Jim,

I test the SmartThreadPool on XP SP2 and don't get these errors.
It seems like a conflict in the performance counters.

Ami
May 28, 2008 at 3:05 PM

how do i resolve the conflict? or diagnose the error

jim

May 28, 2008 at 6:24 PM
Edited May 28, 2008 at 6:49 PM
ami,

i've been searching for more info.  i don't expect you to do any research, but you may know more than me in regards to the perfomance counters.  are the custom counters stored in the perh009.dat (and also registry entries)?  i've found a MS KB that explains how to rebuild the performance counter library library (http://support.microsoft.com/kb/300956).  any help in this area would be appreciated.

i also noticed that within VS that if i expand the servers node for my local server and try to expand the Performance Counters node that i receive the above error message.

thanks

jim
May 28, 2008 at 7:30 PM

ami,

i'm almost 100% sure that the IDE worked prior to testing your sample app (maybe 99.9%).  what could have happened to create this problem?  either way, how can i get it corrected?  if i'm correct about working before your test app, then i feel less guilty about asking for help.

 

jim

Coordinator
May 29, 2008 at 5:40 AM
Hi,

I guess you have something corrupted in your registry. Performance counters information is stored in the registery.
Check the values in your registry of HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Perflib\009
There are two values there: Counter and Help
There format is a line with a number number and then a line with text.

I assume that when the application looks for the performance counter category it gets a line of text instead of a line with number.
This is why you get "Input string was not in a correct format." exception. It tries to parse it as an integer and gets text.

If you want you can copy & paste the values into a file and send to me so I can check and compare it.
Or you can just check it yourself and compare it with another computer.
(Note that the values are different between XP and Vista)

Ami
May 29, 2008 at 2:17 PM

Ami,

Thanks so much for your help.  The registry keys were empty.  I exported them from another XP/SP2 system and I'm back in business.  Not sure how the registry problem was created, but I know how to correct it.

I'll spend more time with you samples now that I can run them on my development system.  Thanks for sharing your threading expertise.

Jim