Jaa


System.FormatException while parsing a string containing valid integer values

Trying to convert a value to an integer using the Parse function might throw a "System.FormatException" with the following following call stack.

Unhandled Exception: System.FormatException: 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.Int16.Parse(String s, NumberStyles style, NumberFormatInfo info)
   [...] ( application specific callstack)

This could arise from a call to one of the Convert.ToIntxx functions ( viz.,ToInt16, ToInt32, ToInt64) or the Intxx.Parse()( Int16.Parse, Int32.Parse or Int64.parse) . The exception is not thrown for any value other than 0.

This is due to corruption of a registry key's value that deals with globalization settings.

The registry key "sPositiveSign" under HKEY_CURRENT_USER\Control Panel\International should be blank for this to work correctly. If this is set to 0 the above exception will occur. Change this value to " " in the registry key to correct this exception.

Note that whenever the value that is parsed is the same as the value for the 'sPositiveSign' item this exception is thrown.

Comments

  • Anonymous
    June 18, 2007
    My company just ran into this on an end users machine. Is there any clue to what application is corrupting the registry? Or more generally, why is this happening?

  • Anonymous
    April 20, 2008
    PingBack from http://stocks-options-trading.info/options-trading/?p=339

  • Anonymous
    August 15, 2013
    The mentioned registry key is balnk in my machine.. But the issue is not resolved.

  • Anonymous
    January 17, 2016
    The mentioned registry key is balnk in my machine.. But the issue is not resolved.