PerformanceCounterCategory.Exists throwing 'Input string was not in a correct format.'

柔情痞子 提交于 2020-01-15 07:00:40

问题


When I'm checking for the existance of a performace category using

PerformanceCounterCategory.Exists("myCategory")

on a system (clean install of XP SP3) where the category doesn't exist I'm getting the following exception thrown ...

    Input string was not in a correct format.
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.CategoryExists(String machine, String category)
       at System.Diagnostics.PerformanceCounterCategory.Exists(String categoryName, String machineName)
       at System.Diagnostics.PerformanceCounterCategory.Exists(String categoryName)

Not wanting to blame the framework :) what am I doing wrong?

EDIT: After checking the Performance Object list - it's full of numbers rather than the normal text - looks like the list is corrupt - going to try this KB


回答1:


Ok. Turned out to be a very corrupt registry. To fix I got (from the KB in the question) perfc009.dat and perfh009.bat from the xp disc (see this KB for expanding off the disc) and popped them into %systemroot%/system32.



来源:https://stackoverflow.com/questions/1152428/performancecountercategory-exists-throwing-input-string-was-not-in-a-correct-fo

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!